+ 2

next() in Python 3

I don't understand next() in Python, can anyone explain?

20th Jul 2018, 2:21 PM
Satyam
7 Antworten
+ 3
x = iter([1,2,3]) #iterator object print(next(x)) #get "next" item print(next(x)) #get "next" item
20th Jul 2018, 2:37 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
example?
20th Jul 2018, 2:35 PM
Satyam
+ 2
Hatsy Rei KrOW I get it but it is strange. Where would we use this?
20th Jul 2018, 2:48 PM
Satyam
+ 1
It get next item from iterator object passed like argument
20th Jul 2018, 2:34 PM
KrOW
KrOW - avatar
+ 1
For understand that you have to understand how create and use objects that implement Iterator protocol
20th Jul 2018, 2:50 PM
KrOW
KrOW - avatar
0
https://code.sololearn.com/cMtsGk7wECzt/?ref=app
20th Jul 2018, 2:47 PM
KrOW
KrOW - avatar