I would like you to consider the following code:
def func(alist):
if len(alist) == 1:
return arg * 2
for item in alist:
yield item * 2
When I run it, I get this error:
SyntaxError: 'return' with argument inside generator
Now, I realize that I cannot do this. However, I would like to know why. What exactly is going on behind the scenes that is causing Python to throw the SyntaxError
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…