标签:imp not found ack col line tricks print lin letter
1.
cities = [‘Marseille‘, ‘Amsterdam‘, ‘New York‘, ‘Londom‘] # the good way for i, city in enumerate(cities): print(i, city)
2.
x_list = [1, 2, 3] y_list = [2, 4, 6] # the good way for x, y in zip(x_list, y_list): print (x, y)
3.
x = 10 y = -10 # the good way x, y = y, x print (‘After: x = %d, y = %d‘ % (x, y))
4.
ages = { ‘Mary‘ : 31, ‘Honathan‘ : 28 } # the good way age = ages.get(‘Dick‘, ‘Unknow‘) print (‘Dick is %s years old‘ % age)
5.
needle = ‘d‘ haystack = [‘a‘, ‘b‘, ‘c‘, ‘d‘] # the good way for letter in haystack: if needle == letter: print (‘Found!‘) break else: print (‘Not found!‘)
6.
# the good way with open(‘pimpin-aint-easy.txt‘) as f: for line in f: print (line)
7.
print (‘Converting!‘) try: print (int(‘1‘)) except: print (‘Conversion failed!‘) else: print (‘Conversion uccessful!‘) finally: print (‘Done!‘)
标签:imp not found ack col line tricks print lin letter
原文地址:http://www.cnblogs.com/xuanyuyt/p/7649720.html