if n>9:
m = int(str(n)[::-1])
while n == m :
yield n
else:
yield n
def nothuishu(x):
if x in first:
while x < 1000:
yield x
>>> first(4)
>>> next(first)
Traceback (most recent call last):
File "
TypeError: 'function' object is not an iterator
>>> from collections import Iterable
>>> isinstance(first,Iterable)
False
>>> isinstance(nothuishu,Iterable)
False
>>> from collections import Iterator
>>> isinstance(nothuishu,Iterator)
False
小白求问:
为什么我定义的两个函数都不是Iterable、Iterator?
但是nothuishu(1000)输出的是生成器会输出的东西呀
只要是一个个的就可以迭代吧,这样写哪里不对?