September 2026
1051 pages
35h 4m
English
Because data types and classes were unified in Python 2.3, Python is object-oriented from the ground up. This means that basically everything you come across when using Python is an instance of some class. From the simple number to the classes[ 94 ] themselves, each object has its own attributes and methods.
In particular, it’s possible to inherit from built-in data types such as list or dict.
The following example implements a subclass of list that automatically sorts its elements after each change:
class SortedList(list): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.sort() def __setitem__(self, key, value): super().__setitem__(key, value) self.sort() def append(self
Read now
Unlock full access