python 遍历
-
Sequence
l = [1,2,3,4,5] for i in l: print(i) #Showing:1 2 3 4 5 for i in range(len(l)): print('idx: %d, val: %d' % (i,l[i]))
-
Dictionary
d = {'1':1, '2':2, '3':3} for k in d.keys(): print(d[i]) for v in d.values(): print(i) for k,v in d.items(): print(k, v)
-
Advanced method
l = [1,2,3,4,5] for idx,val in enumerate(l): print(idx, val)
l_name = ['一', '二', '三'] l_val = [1,2,3] for name,val in zip(l_name, l_val): print(name, val)