9. Custom Behavior of Classes
In Python, class method names that start and end with __ are referred to as special methods because they allow us to customize the way Python will use our classes. In this chapter, we look at some of these methods and learn how to achieve compatibility in both Python 2 and 3. We first look at the custom iterator methods (__iter__ and __next__) and then later discuss the __str__, and __nonzero__ methods.
Custom Iterators
Iterators in Python and other languages are objects that can be iterated. Iterators are all over Python. They have been subconsciously implemented in ...