What do you call the item of list when used as an iterator in a for loop?
<p>I'm not sure how you name the <code>n</code> in the following <code>for</code> loop. Is there are a term for it? </p>

<pre><code>for n in [1,2,3,4,5]:
    print i
</code></pre>

<p>And, am I correct that the list itself is the <code>iterator</code> of the <code>for</code> loop ? </p>

<p>While <code>n</code> is called a <em>loop variable</em> the list is absolutely <strong>not</strong> an iterator. It is iterable object, i.e. and <em>iterable</em>, but it is not an <em>iterator</em>. An iterable may be an iterator itself, but not always. That is to say, iterators are iterable, but not all iterables are iterators. In the case of a <code>list</code> it is simply an iterable. </p>

<p>It is an iterable because it implements an <code>__iter__</code> method, which returns an iterator:</p>

<p>From the <a href="https://docs.python.org/3/glossary.html#term-iterable" rel="nofollow">Python Glossary</a> an <strong>iterable</strong> is:</p>

<blockquote>
  <p>An object capable of returning its members one at a time. Examples of
  iterables include all sequence types (such as list, str, and tuple)
  and some non-sequence types like dict, file objects, and objects of
  any classes you define with an <code>__iter__()</code> or <code>__getitem__()</code> method.
  Iterables can be used in a for loop and in many other places where a
  sequence is needed (zip(), map(), ...). <strong>When an iterable object is
  passed as an argument to the built-in function <code>iter()</code>, 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 iter() or deal with iterator objects yourself. The for statement
  does that automatically for you, creating a temporary unnamed variable
  to hold the iterator for the duration of the loop.</strong>    </p>
</blockquote>

<p>So, observe:    </p>

<pre><code>&gt;&gt;&gt; x = [1,2,3]
&gt;&gt;&gt; iterator = iter(x)
&gt;&gt;&gt; type(iterator)
&lt;class 'list_iterator'&gt;
&gt;&gt;&gt; next(iterator)
1
&gt;&gt;&gt; next(iterator)
2
&gt;&gt;&gt; next(iterator)
3
&gt;&gt;&gt; next(iterator)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
StopIteration
</code></pre>

<p>It is illuminating to understand that a for-loop in Python such as the following:</p>

<pre><code>for n in some_iterable:
    # do something
</code></pre>

<p>is equivalent to:</p>

<pre><code>iterator = iter(some_iterable)
while True:
    try:
        n = next(iterator)
        # do something
    except StopIteration as e:
        break
</code></pre>

<p>Iterators, which are returned by a call to an object's <code>__iter__</code> method, also implement the <code>__iter__</code> method (usually returning themselves) but they <strong>also</strong> implement a <code>__next__</code> method. Thus, an easy way to check if something is an iterable is to see if it implements a <strong>next</strong> method</p>

<pre><code>&gt;&gt;&gt; next(x)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
TypeError: 'list' object is not an iterator
</code></pre>

<p>Again, from the <a href="https://docs.python.org/3/glossary.html#term-iterator" rel="nofollow">Python Glossary</a>, an <strong>iterator</strong> is:</p>

<blockquote>
  <p>An object representing a stream of data. Repeated calls to the
  iteratorâs <code>__next__()</code> method (or passing it to the built-in function
  <code>next()</code>) return successive items in the stream. When no more data are
  available a StopIteration exception is raised instead. At this point,
  the iterator object is exhausted and any further calls to its
  <code>__next__()</code> method just raise StopIteration again. <strong>Iterators are required to have an <code>__iter__()</code> 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 list) produces a fresh new iterator each time you pass it
  to the iter() function or use it in a for 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.</strong></p>
</blockquote>

<p>I've illustrated the bevahior of an iterator with the <code>next</code> function above, so now I want to concentrate on the bolded portion.</p>

<p>Basically, an iterator can be used in the place of an iterable because iterators are always iterable. However, an iterator is good for only a single pass. So, if I use a non-iterator iterable, like a list, I can do stuff like this:</p>

<pre><code>&gt;&gt;&gt; my_list = ['a','b','c']
&gt;&gt;&gt; for c in my_list:
...   print(c)
... 
a
b
c
</code></pre>

<p>And this:</p>

<pre><code>&gt;&gt;&gt; for c1 in my_list:
...   for c2 in my_list:
...     print(c1,c2)
... 
a a
a b
a c
b a
b b
b c
c a
c b
c c
&gt;&gt;&gt; 
</code></pre>

<p>An iterator behaves almost in the same way, so I can still do this:</p>

<pre><code>&gt;&gt;&gt; it = iter(my_list)
&gt;&gt;&gt; for c in it:
...   print(c)
... 
a
b
c
&gt;&gt;&gt; 
</code></pre>

<p>However, iterators do not support multiple iteration (well, you can make your an iterator that does, but generally they do not):</p>

<pre><code>&gt;&gt;&gt; it = iter(my_list)
&gt;&gt;&gt; for c1 in it:
...   for c2 in it:
...     print(c1,c2)
... 
a b
a c
</code></pre>

<p>Why is that? Well, recall what is happening with the iterator protocol which is used by a <code>for</code> loop under the hood, and consider the following:</p>

<pre><code>&gt;&gt;&gt; my_list = ['a','b','c','d','e','f','g']
&gt;&gt;&gt; iterator = iter(my_list)
&gt;&gt;&gt; iterator_of_iterator = iter(iterator)
&gt;&gt;&gt; next(iterator)
'a'
&gt;&gt;&gt; next(iterator)
'b'
&gt;&gt;&gt; next(iterator_of_iterator)
'c'
&gt;&gt;&gt; next(iterator_of_iterator)
'd'
&gt;&gt;&gt; next(iterator)
'e'
&gt;&gt;&gt; next(iterator_of_iterator)
'f'
&gt;&gt;&gt; next(iterator)
'g'
&gt;&gt;&gt; next(iterator)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
StopIteration
&gt;&gt;&gt; next(iterator_of_iterator)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
StopIteration
&gt;&gt;&gt; 
</code></pre>

<p>When I used <code>iter()</code> on an iterator, it returned itself!</p>

<pre><code>&gt;&gt;&gt; id(iterator)
139788446566216
&gt;&gt;&gt; id(iterator_of_iterator)
139788446566216
</code></pre>

python terminology