Python Built-in Functions

Learn how Python’s built-in functions leverage duck typing and facilitate common operations across various data types.

There are numerous functions in Python that perform a task or calculate a result on certain types of objects without being methods on 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, but let’s quickly go through the important ones and pick up a few neat tricks along the way.

The len() function

One simple example of functions that are related to object methods is the len() function, which returns the number of items in some kind of container object, such as a dictionary or list. We’ve seen it before, demonstrated as follows:

Get hands-on with 1200+ tech skills courses.