dict | #默认情况下,dict迭代的是key | 迭代value | #迭代key,value |
for value in d.itervalues(): | for k,v in d.iteritems(): | ||
#迭代字符串 | for ch in 'ABCD123': | ||
#判断是否是可迭代对象isinstance | 字符串 | list | |
from collections import Iterable | isinstance('abc',Iterable) | isinstance([1,2,3],Iterable) | isinstance(123,Iterable) |
enumerate
函数
for i,value in enumerate(['a','b','c']): print i,value