迭代器和生成器


1.列表生成式 [x for x in dir(os) if not x.startswith('_')]
2.生成器  
生成器写法一:
(x for x in dir(os))
生成器写法二:
def f():
    yield


调用方式:
a.__next__()
next(a)
for循环
send() 

生成器中全部调用完返回 stopiteration

3.迭代器 iterator
拥有__next__() 方法和__iter__() 方法的对象