def iterator(): i=1 while True: yield i i += 1 o = iterator()
while True: try: x = next(o) print(x) except StopIteration: break
异常处理部分就不用加了吧,既然是全体整数,说明没有上限的...
Sign in to make a reply
BillCode
输出全体整数
def iterator(): i=1 while True: yield i i += 1 o = iterator()
while True: try: x = next(o) print(x) except StopIteration: break