030 迭代器 生成器
作者:互联网
""" 目录: 一 迭代 二 可迭代对象 三 迭代器 四 生成器 """
一 迭代
''' 迭代: 一种操作,逐个获取数据过程。 for...in... '''
二 可迭代对象
# 判断可迭代对象 from collections.abc import Iterable if __name__ == '__main__': type_1 = 123 print(type(type_1), isinstance(type_1, Iterable)) # False type_2 = "abc" print(type(type_2), isinstance(type_2, Iterable)) # True type_3 = [1, 2, 3] print(type(type_3), isinstance(type_3, Iterable)) # True type_4 = (1, 2, 3) print(type(type_4), isinstance(type_4, Iterable)) # True type_5 = {"name": "Tome"} print(type(type_5), isinstance(type_5, Iterable)) # True type_6 = {"name", "Tome"} print(type(type_6), isinstance(type_6, Iterable)) # True ''' <class 'int'> False <class 'str'> True <class 'list'> True <class 'tuple'> True <class 'dict'> True <class 'set'> True '''
三 迭代器
四 生成器
标签:迭代,True,生成器,print,030,isinstance,type,Iterable 来源: https://www.cnblogs.com/huafan/p/16462451.html