Let me check it out.
def foo():
print('In foo')
return range(5)
Now, if I call ( ) fooat the beginning of the loop , it should print as many times as it is called / evaluated.forfor _ in foo()In foo
So,
for _ in foo():
pass
In foo
And is called only once. The value was evaluated only once.
source
share