iterable terminology (for language lawyers)

Raymond Hettinger python at rcn.com
Wed Mar 16 04:24:22 EST 2005


Michele Simionato]
> According to the standand library
> (http://docs.python.org/lib/typeiter.html)
> an *iterable* is something with an __iter__ method. This means that
> strings are *not* iterable.

The referenced section also says, "Sequences, described below in more
detail, always support the iteration methods."  And since strings are
sequences, strings
*are* iterable.



> The reason why I ask for a clarification is that I am going to
> give a course at the ACCU conference, so I want to
> make sure I use the rigth terminology.

You're best bet is to quote the tutorial's glossary,
http://docs.python.org/tut/node18.html :

iterable
    A container 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 and file and objects
of any classes you define with an __iter__() or __getitem__() method.
Iterables can be used in a for loop and in many other places where a
sequence is needed (zip(), map(), ...). When an iterable object is
passed as an argument to the builtin function iter(), 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. See also iterator,
sequence, and generator.


Raymond Hettinger




More information about the Python-list mailing list