Python Forum
Learning python specific syntax after using other scripting languages for years
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Learning python specific syntax after using other scripting languages for years
#5
Note. This is in python 3. if you using python 2. I would suggest you jump over to python 3.

1. Python is strongly type but it all underneath the hood.

2. You use the best loop for the job. You should never delete an item in a for loop.
but in a while loop you can make adjustments.

example
# Python is strongly type. You just don't see it
def myfunction():
	pass
	
a = {}
b = []
c = (1,1)
	
print(type(1))
print(type('word'))
print(type(0.5))
print(type(a))
print(type(b))
print(type(c))
print(type(c[0])) # first element
print(type(myfunction))

print()
a = {'one': 2, 3:4, 5:'six'}
for key in a: # just loop over keys
	print(key)

print()	
for key, value in a.items(): # iter over (key, value)
	print(key, value)
	
print()	
for key in a.keys(): # iter of keys
	print(key)

print()	
for value in a.values(): # iter over values
	print(value)
	
a = dict([(key, value * 2) for key, value in a.items()])
print(a)
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
RE: Learning python specific syntax after using other scripting languages for years - by Windspar - Dec-11-2017, 03:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting days to years in loop while computing values across grid cells Lightning1800 2 2,683 May-15-2018, 08:44 PM
Last Post: Lightning1800

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020