Most readers are aware that Python is an object-oriented language. By object-oriented, we mean that Python can define classes, which bundle data and functionality into one entity. For example, we may create a class IntContainer
which stores an integer and allows certain operations to be performed:
A Primer on Python Metaclasses
class IntContainer(object):
def __init__(self, i):
self.i = int(i)
def add_one(self):
self.i += 1
ic = IntContainer(2)
ic.add_one()
print(ic.i)
This is a bit of a silly example, but shows the fundamental nature of classes: their ability to bundle data and operations into a single object, which leads to cleaner, more manageable, and more adaptable code. Additionally, classes can inherit properties from parents and add or specialize attributes and methods. This object-oriented approach to programming can be very intuitive and powerful.
What many do not realize, though, is that quite literally everything in the Python language is an object.