Deitel Presents Introduction to Python Iterators
In this article, we motivate the need for iterators and define a class that supports iterators. Iterators are new to the Python language--they were added in version 2.2. Classes that hold sequences of values are prime candidates for iterators. If a class supports iterators, then a client of the class can use a for loop to progress through the items in the class's sequence. Readers should be familiar with OOP (constructors, the object reference argument, private attributes, class customization) and exception handling. The code examples included in this article show readers examples using the Deitel™ signature LIVE-CODE™ Approach.