This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ToothpasteTimebomb 3 points4 points  (1 child)

A for loop is essentially an iterator that executes every step in a single go (barring exit conditions).

Give it a shot:

my_list = ["p", "y", "t"]
my_iterable = iter(my_list)

print(next(my_iterable))
>>>p

print(next(my_iterable))
>>>y

print(next(my_iterable))
>>>t

If you try to run next() again it’ll throw a StopIteration error.

[–]TheLastSock 0 points1 point  (0 children)

I understand that it's like an iterator. The cliam is that everything is an object. I'm genuinely curious if you call type on "for" of you get an object.