Understanding Attributes, Dicts and Slots in Python
Understanding Attributes in Python
Python is a very dynamic language by nature. Variables do not need to be declared and can be added as attributes almost everywhere. Consider an empty class like this:
class MyClass:
pass
This is a complete definition of a class in Python. Granted, it does nothing, but it’s still valid.
At any later point in time, we can “patch” attributes to our class like this:
MyClass.class_attribute = 42
The class has this new class_attribute
value from that point on.