+ 3
Why not "def"?
it=iter('abcdef') for i in range (3,6): print (next(it), end="")
11 odpowiedzi
+ 6
Your for loop will run 3 times. Then print a,b,c.
+ 6
I am testing here. See I can print "def " using test= "abcdef".
See this code.
https://code.sololearn.com/crfhY0Oobo65/?ref=app
+ 4
Navneet Ghosh
Try this
for i in range (196,199):
print (next(it), end="")
It will print "abc" as well.
+ 3
Why def?
+ 2
it=iter('abcdef')
for i in range (3):
next(it)
for i in range (3):
print (next(it), end="")
+ 2
iter creates an iterator. Next pops out the next item.
That's like when you get a soda from the vending machine:
You hit the button, first can comes out.
+ 1
Oma Falk output is abc not def
+ 1
Navneet Ghosh did u understand why not def?
+ 1
I thought you meant why not a function but I get it now.
0
Oma Falk little bit
As commented above that loop will run 3 times and after that iteration will work
0
I have test ur logic and reached on a conclusion that u were printed iter value within the for loop which was iterating 3 time that is why u got abc.
IF YOU iterated range(6) instead of range(3,6), then you would got entirely string....
IF u r agree to my answer so, plz thumb up which will help others to view my answer.
https://code.sololearn.com/cQPgsvaQ9TOm/?ref=app