-
Book Overview & Buying
-
Table Of Contents
Python Object-Oriented Programming - Fifth Edition
By :
There are numerous functions in Python that perform a task or calculate a result on certain types of objects without seeming to involve obvious methods of the underlying class. They usually abstract common calculations that apply to multiple types of classes. This is duck typing at its best; these functions accept objects that have certain attributes or methods, and are able to perform generic operations using those methods. We’ve used many of the built-in functions already. We’ll take a look at three common ones:
The len() function
The reversed() function
The enumerate() function
We’ll start with the len() function.
The len() function returns the number of items in some kind of container object, such as a dictionary, set, tuple, or list. You’ve seen it before, demonstrated...