Why is the output of the following python code is abc? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Why is the output of the following python code is abc?

it=iter('abcdef') for i in range(3,6): print(next(it), end=' ')

9th Jun 2019, 7:52 PM
Rishu Kumar
Rishu Kumar - avatar
1 Answer
+ 5
I don't know but I guess that probably iter('abcdef') creates an iterator with which you can iterate throw the String 'abcdef' using the function "next()". the Iterator would return the char at the position it's at. since the for-loop is executed 3 times the fist 3 characters of the oterator get printed just guessing... hope that helped! happy coding! 😄
9th Jun 2019, 9:45 PM
Anton Böhler
Anton Böhler - avatar