Can someone pls help me understand these lines of code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Can someone pls help me understand these lines of code?

what is the output of the code? A = [1,2,3,4,5,6,7] G = iter(A) next(G) for num in G: print(num) next(G) next(G) #Output : 2 5 https://code.sololearn.com/c30YB0E3gUu4/?ref=app

17th Sep 2020, 3:20 AM
Twilight🌅
Twilight🌅 - avatar
3 Answers
+ 4
thanks for helping me understand :) Jan Markus & Akash Agrawal
17th Sep 2020, 4:58 AM
Twilight🌅
Twilight🌅 - avatar
+ 2
A = [1,2,3,4,5,6,7] G = iter(A) # This is iterable right next(G) #1 #when you print print(next(G)) #you give 1 #next(G) #now you print(next(G)) #you give 2 #This is a another method of for loops. for num in G: print(num) #2 #5 next(G) #3 #6 next(G) #4 #7 #Output : 2 5
17th Sep 2020, 4:00 AM
Akash Agrawal
Akash Agrawal - avatar
+ 1
Why didn't 3 and 4 print
17th Sep 2020, 6:23 AM
Jason Kennedy