时间:2021-07-01 10:21:17 帮助过:205人阅读
判断一个对象是不是可迭代对象:
from collections import Iterable isinstance(list(range(100)), Iterable) isinstance('Say YOLO Again.')
列表:
相关推荐:《python视频教程》
L = list(range(100))for i in L: print(i)
元组:
T = tuple(range(100))for i in T: print(i)
字典:
dic = {'name': 'chen', 'age': 25, 'loc': 'Tianjin'} # 以列表的形式返回 keylist(dic.keys()) # 以列表的形式返回 valuelist(dic.values()) # 循环key for key in dic: print(key) # 循环value for value in dic.values(): print(value) # 循环key, value for key, value in dic.items(): print(key, value)
字符串:
S = 'Say YOLO Again!'for s in S: print(s) 返回'索引-元素'对: for i, value in enumerate('Say YOLO Again.'): print(i, value)
以上就是python中可迭代对象有哪些的详细内容,更多请关注Gxl网其它相关文章!