模仿for循环迭代可迭代对象,
# for i in Iterable:
# iterable >>> 迭代器。iterator
# 可迭代对象 iterable
# 迭代器。iterator
# re = range(5).__iter__()
# print(re)
# print(re.__next__())
# print(re.__next__())
# print(re.__next__())
# print(re.__next__())
# print(re.__next__())
# print(re.__next__())
# StopIteration
# for i in iterable:
# pass
# for 循环迭代可迭代对象的时候是怎么做的?
# 会把可迭代对象(iterable)
# 调用__iter__()函数转换成
# 迭代器(iterator)
# 然后调用__next__()函数获取一个元素
re = [i for i in range(9)]
# print(re)
可迭代对象 iterable
迭代器 iterator
生成器 generator
ge = (i for i in range(9))
print(ge)
# print(re.__next__())
for i in ge:
print(i)