mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 15:24:09 +03:00
Merge pull request #1175 from genkimarshall/python3-next
[python3/en] Use `next()` instead of `__next__()`
This commit is contained in:
commit
a255cbe26e
@ -394,15 +394,15 @@ our_iterable[1] # Raises a TypeError
|
|||||||
our_iterator = iter(our_iterable)
|
our_iterator = iter(our_iterable)
|
||||||
|
|
||||||
# Our iterator is an object that can remember the state as we traverse through it.
|
# Our iterator is an object that can remember the state as we traverse through it.
|
||||||
# We get the next object by calling the __next__ function.
|
# We get the next object with "next()".
|
||||||
our_iterator.__next__() #=> "one"
|
next(our_iterator) #=> "one"
|
||||||
|
|
||||||
# It maintains state as we call __next__.
|
# It maintains state as we iterate.
|
||||||
our_iterator.__next__() #=> "two"
|
next(our_iterator) #=> "two"
|
||||||
our_iterator.__next__() #=> "three"
|
next(our_iterator) #=> "three"
|
||||||
|
|
||||||
# After the iterator has returned all of its data, it gives you a StopIterator Exception
|
# After the iterator has returned all of its data, it gives you a StopIterator Exception
|
||||||
our_iterator.__next__() # Raises StopIteration
|
next(our_iterator) # Raises StopIteration
|
||||||
|
|
||||||
# You can grab all the elements of an iterator by calling list() on it.
|
# You can grab all the elements of an iterator by calling list() on it.
|
||||||
list(filled_dict.keys()) #=> Returns ["one", "two", "three"]
|
list(filled_dict.keys()) #=> Returns ["one", "two", "three"]
|
||||||
|
Loading…
Reference in New Issue
Block a user