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