__init__()self
_var__var
@property@var.setter
@property and @var.setter provide a Pythonic interface that encapsulates internal
logic while maintaining a clean, attribute-like syntax for the user with a never-changing API.
super()
@abstractmethod, that all its subclasses
must implement, ensuring a consistent interface while preventing the base class itself from being instantiated.
Mixin by convention.
__str__
and debugging-friendly for developers __repr__.
__add__ (+), __sub__ (-), and __mul__ (*), etc.,
allowing custom objects work with standard mathematical syntax, making them behave like built-in numeric types.
__len__ (length) and __getitem__ (indexing), such that
your class can be treated like a list or dictionary, allowing them to be indexed, sliced, or measured.
__init__ initializes an instance, __new__ (a
magic class method) handles the memory allocation and returns the object (often used in Singleton),
__call__ allows an instance to be executed like a function.
==, <, >, enabling
objects to be sorted or filtered based on specific attributes.
@classmethodcls) as the first argument instead of an instance,
primarily used for Factory Patterns.
@staticmethodself or cls), like a regular
function living in the class's namespace for logical grouping; mostly for utility functions needing no access to
class or instance data.
@dataclassdataclass is a class decorator that automates the generation of boilerplate code for data-oriented
objects, primarily by synthesizing methods like __init__, __repr__, and
__eq__ based on type hints.
__dict__
__dict__
__slot__
__slots__
__getattr____dict__ or class tree. It allows you to dynamically handle missing attributes, making it perfect for
creating "wrappers" or "proxies."
type as the metaclass for all classes. When you define
class MyClass:, behind the scenes, Python actually executes type("MyClass", (), {}).
getattr(),
setattr(), hasattr(), and delattr().