检测对象是否属于可迭代的
1 from collections import Iterable 2 # 可迭代对象的本质:对象所属的类中包含了__iter__()方法 3 # 检测一个对象是否可以迭代,用isinstance函数检测 4 arc = isinstance([1,2,3],Iterable) 5 print(arc) #True 6 arc = isinstance((1,2,3),Iterable) 7 print(arc) #True 8 arc = isinstance({"name":"黄秋生"},Iterable) 9 print(arc)#True 10 arc = isinstance("xiaoming",Iterable) 11 print(arc)#True 12 arc = isinstance(3,Iterable) 13 print(arc)#False