3 ms·
More than just built in functions, any object that defines a __len__ and a __index__ method (that provide len(x) and x[0] respectively) can also be iterated ove
by orf 11y ago
More than just built in functions, any object that defines a __len__ and a __index__ method (that provide len(x) and x[0] respectively) can also be iterated over in a for loop ('for item in instance'). A good reference for magic methods is [1] for anyone interested.
1. http://www.rafekettler.com/magicmethods.html http://www.rafekettler.com/magicmethods.html