Python“三大器”之迭代器
迭代器
1、什么是迭代器
迭代:迭代指的是重复迭代,每一次迭代的结果都是基于上一次而来的
迭代器:指的是迭代取值的工具,可以迭代取值”“‘’‘’
2、可迭代对象
可迭代对象: 所有的序列类型:str,list,tuple,dict,set,file都是可迭代对象
凡是内部有.__iter__()方法的都是可迭代对象
# 字符串
str.__iter__()
# 元组
tuple.__iter__()
# 列表
list.__iter__()
# 字典
dict.__iter__()
# 集合
set.__iter__()
# 文件
file = open("dir/passwd.txt", "r", encoding="utf-8")
file.__iter__()

![Python“三大器”之迭代器[Python常见问题]](https://www.zixueka.com/wp-content/uploads/2023/10/1696830767-1b0be9a6b4cad98.jpg)
