0
Python-can anybody pls xplain this
ls=[2,4,1,"bars",0,"foo",9] it=iter(ls[1:]) print(next(it),end="0") next(it) next(it) print(it.__next__())
3 Respuestas
+ 6
In the second line, an iterator is created that contains the elements [1:] of the list (4, 1, 'bars', 0, 'foo', and 9).
Both next(it) and it.__next__() call the next item of the iterator.
In line 3, the first item (4) is called and printed and '0' is appended.
In lines 4 and 5, the next items (1 and 'bars') are called, but nothing happens with them (especially they are not printed), so they are just lost.
In the last line, the next element (0) is printed, so the whole result is '400'.
+ 2
You're welcome
+ 1
thank you