Reading Time: 1 minutes
Customizing builtin data types in Python
str, int, dict, tuple, list, float, bool, set, are all Python classes. This means that we can subclass them and devise our own classes which behave the same way as the built-in types, and at the same time, give us the option of customize selected functionality.
>>> class MyInt(int): def __add__(self, value): print("Adding...") return int.__add__(self, value) >>> a = MyInt(5) >>> a + 6 Adding... 11