If I execute,
a = iter([1,2,3])
for x in a:
print(x)
if x==1:
z=next(a)
I get
1
3
which I expect, since the call to next
advances the iterator and skips the 2
.
However in interactive mode (command line), if I remove the z=
assignment, and only call next
, it behaves very differently.
>>> a = iter([1,2,3])
>>> for x in a:
... print(x)
... if x==1:
... next(a)
gives me
1
2
3
I'm using Python 3.8.8 in Windows 64 bits. Is this expected? It only happens in interactive mode.