summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGeoff Liu <cangming.liu@gmail.com>2015-07-24 15:04:04 -0600
committerGeoff Liu <cangming.liu@gmail.com>2015-07-24 15:04:04 -0600
commita255cbe26ed165f586e5c61ea316fcf6c26f4824 (patch)
tree818cbea9cc14e5d9fde1dd33133484c299234164
parentbd998e10a8bd0f7c79223d861b42a4a6238ce9ec (diff)
parentac2dfe7dc782cf1663944c0de48f6bbe810a56d8 (diff)
Merge pull request #1175 from genkimarshall/python3-next
[python3/en] Use `next()` instead of `__next__()`
-rw-r--r--python3.html.markdown12
1 files changed, 6 insertions, 6 deletions
diff --git a/python3.html.markdown b/python3.html.markdown
index 36298566..9d965fb1 100644
--- a/python3.html.markdown
+++ b/python3.html.markdown
@@ -394,15 +394,15 @@ our_iterable[1] # Raises a TypeError
our_iterator = iter(our_iterable)
# 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.
-our_iterator.__next__() #=> "one"
+# We get the next object with "next()".
+next(our_iterator) #=> "one"
-# It maintains state as we call __next__.
-our_iterator.__next__() #=> "two"
-our_iterator.__next__() #=> "three"
+# It maintains state as we iterate.
+next(our_iterator) #=> "two"
+next(our_iterator) #=> "three"
# 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.
list(filled_dict.keys()) #=> Returns ["one", "two", "three"]