Everything Is an Object in Python — Learn to Use Functions as Objects

Just like str, int, and dict, functions are also objects in Python. Find out how we can take advantage of this feature to write more flexible code.

The Startup
Published in
5 min readFeb 28, 2020

--

You’ve probably heard the saying that everything is an object in Python — one of the most popular object-oriented languages. When we talk about objects, we usually refer an object to a collection of data, commonly known as attributes, and the object has certain predefined functions to update these data or exchange data with other objects.

Data Types as Objects

All data types, such as numbers, strings, lists, and dictionaries, are all objects in Python. Using a tangible example, you can think about them physically as boxes of data. In terms of size, some boxes are smaller by just holding an int, a bool, or a str, while some boxes are larger by holding a list or a dict. The difference is their size reflects the needed memory for storing these data in the computer. Certainly, boxes can have other characteristics, such as color and material, for which you can conceptualize them as different types of data associated with each box.

--

--

Yong Cui
The Startup

Work at the nexus of biomedicine, data science & mobile dev. Author of Python How-to by Manning (https://www.manning.com/books/python-how-to).