<div dir="ltr"><dt id="term-iterable" style="font-weight:bold;font-size:1.1em;font-family:"Lucida Grande",Arial,sans-serif">iterable</dt><dd style="margin-top:3px;margin-bottom:10px;margin-left:30px;text-align:justify;line-height:20.8px;font-family:"Lucida Grande",Arial,sans-serif;font-size:16px">An object capable of returning its members one at a time. Examples of iterables include all sequence types (such as <a class="" href="https://docs.python.org/3.6/library/stdtypes.html#list" title="list" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">list</span></code></a>, <a class="" href="https://docs.python.org/3.6/library/stdtypes.html#str" title="str" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">str</span></code></a>, and <a class="" href="https://docs.python.org/3.6/library/stdtypes.html#tuple" title="tuple" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">tuple</span></code></a>) and some non-sequence types like <a class="" href="https://docs.python.org/3.6/library/stdtypes.html#dict" title="dict" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">dict</span></code></a>,<a class="" href="https://docs.python.org/3.6/glossary.html#term-file-object" style="color:rgb(0,176,228)"><span class="">file objects</span></a>, and objects of any classes you define with an <a class="" href="https://docs.python.org/3.6/reference/datamodel.html#object.__iter__" title="object.__iter__" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">__iter__()</span></code></a> or <a class="" href="https://docs.python.org/3.6/reference/datamodel.html#object.__getitem__" title="object.__getitem__" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">__getitem__()</span></code></a> method. Iterables can be used in a <a class="" href="https://docs.python.org/3.6/reference/compound_stmts.html#for" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">for</span></code></a> loop and in many other places where a sequence is needed (<a class="" href="https://docs.python.org/3.6/library/functions.html#zip" title="zip" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">zip()</span></code></a>, <a class="" href="https://docs.python.org/3.6/library/functions.html#map" title="map" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">map()</span></code></a>, ...). When an iterable object is passed as an argument to the built-in function <a class="" href="https://docs.python.org/3.6/library/functions.html#iter" title="iter" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">iter()</span></code></a>, it returns an iterator for the object. This iterator is good for one pass over the set of values. When using iterables, it is usually not necessary to call <a class="" href="https://docs.python.org/3.6/library/functions.html#iter" title="iter" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">iter()</span></code></a> or deal with iterator objects yourself. The <code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:rgb(236,240,243)"><span class="">for</span></code> statement does that automatically for you, creating a temporary unnamed variable to hold the iterator for the duration of the loop. See also <a class="" href="https://docs.python.org/3.6/glossary.html#term-iterator" style="color:rgb(99,99,187);text-decoration:none">iterator</a>, <a class="" href="https://docs.python.org/3.6/glossary.html#term-sequence" style="color:rgb(99,99,187);text-decoration:none">sequence</a>, and <a class="" href="https://docs.python.org/3.6/glossary.html#term-generator" style="color:rgb(99,99,187);text-decoration:none">generator</a>.</dd><dt id="term-iterator" style="font-weight:bold;font-size:1.1em;font-family:"Lucida Grande",Arial,sans-serif">iterator</dt><dd style="margin-top:3px;margin-bottom:10px;margin-left:30px;text-align:justify;line-height:20.8px;font-family:"Lucida Grande",Arial,sans-serif;font-size:16px"><p class="" style="line-height:22.4px;margin-top:0px!important">An object representing a stream of data. Repeated calls to the iterator’s <a class="" href="https://docs.python.org/3.6/library/stdtypes.html#iterator.__next__" title="iterator.__next__" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">__next__()</span></code></a> method (or passing it to the built-in function <a class="" href="https://docs.python.org/3.6/library/functions.html#next" title="next" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">next()</span></code></a>) return successive items in the stream. When no more data are available a <a class="" href="https://docs.python.org/3.6/library/exceptions.html#StopIteration" title="StopIteration" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">StopIteration</span></code></a> exception is raised instead. At this point, the iterator object is exhausted and any further calls to its <code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">__next__()</span></code> method just raise<a class="" href="https://docs.python.org/3.6/library/exceptions.html#StopIteration" title="StopIteration" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">StopIteration</span></code></a> again. Iterators are required to have an <a class="" href="https://docs.python.org/3.6/reference/datamodel.html#object.__iter__" title="object.__iter__" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">__iter__()</span></code></a> method that returns the iterator object itself so every iterator is also iterable and may be used in most places where other iterables are accepted. One notable exception is code which attempts multiple iteration passes. A container object (such as a <a class="" href="https://docs.python.org/3.6/library/stdtypes.html#list" title="list" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">list</span></code></a>) produces a fresh new iterator each time you pass it to the <a class="" href="https://docs.python.org/3.6/library/functions.html#iter" title="iter" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">iter()</span></code></a> function or use it in a <a class="" href="https://docs.python.org/3.6/reference/compound_stmts.html#for" style="color:rgb(99,99,187);text-decoration:none"><code class="" style="padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px;background-color:transparent"><span class="">for</span></code></a> loop. Attempting this with an iterator will just return the same exhausted iterator object used in the previous iteration pass, making it appear like an empty container.</p><p class="" style="margin-top:0px;line-height:22.4px">More information can be found in <a class="" href="https://docs.python.org/3.6/library/stdtypes.html#typeiter" style="color:rgb(99,99,187);text-decoration:none">Iterator Types</a>.</p></dd></div>