'In Python3, Why list object is an iterable but not iterator directly?

I do know object implemented iter() is a iterable, and next is a iterator. but i'm confused why list object in python3 doesn't implement next directly.

l = list((1,2,3))
l_iterator = l.__iter__()
l_iterator.__next__() 
...

is there some ingenious mechanism i missed?



Solution 1:[1]

You only need to use the double underscores when defining iterator and next methods for a custom class. I think in this case, here is what you are looking to do:

l = list((1,2,3))
l_iterator = iter(l)
next(l_iterator)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonSquiggs