def f1(): print(11) yield 1 print(22) yield 2 print(33) yield 3 r = f1() r1 = r.__next__() print(r1) r1 = r.__next__() print(r1) r1 = r.__next__() print(r1)
11
1
22
2
33
3
range 生成原理 def f1(n): start = 0 while True: if start > n: return else: yield start start += 1 r = f1(3) r1 = r.__next__() print(r1) r1 = r.__next__() print(r1) r1 = r.__next__() print(r1)
def f1(n): start = 0 while True: if start > n: return else: yield start start += 1 for i in f1(3): print(i)
0
1
2
3