#def func(param):
# if param < 0:
# return "test"
# i = 0
# while i < param:
# yield i
# i += 1
def func(param):
if param < 0:
return "test"
def gen(n):
i = 0
while i < param:
yield i
i += 1
return gen(param)
print(func(-1))
print(func(3))
g = func(3)
for i in range(0, 3):
print(next(g))
Python解释器是否有原因无法将注释代码隐式转换为实际代码?这似乎应该被允许,但我想知道有什么影响让他们选择不允许这样做。