Browse by Topic

Popular

Latest

Latest Posts

Editorial illustration of the Python + operator connecting two objects through the __add__ special method
Python

Python __add__: Overloading the + Operator

Learn how Python's __add__ method powers the + operator, how to return NotImplemented for unsupported types, and how __radd__ and __iadd__ extend addition.

operator overloadingdunder methodsPython data modelspecial methods
A Python class diagram showing operator symbols like + and == connecting to magic method names such as __add__ and __eq__.
Python

Python Magic Methods and Operator Overloading

Learn how to overload operators in Python with magic methods like __add__, __eq__, and __lt__. See reflected and in-place operators, comparison behavior, and common pitfalls.

PythonOperator OverloadingMagic MethodsDunder Methods
Diagram showing a Python class blueprint with attributes and methods, an inheritance arrow, and a speedometer icon to represent slots.
Python

Python Class: Attributes, Methods, and Inheritance

A practical guide to Python classes: instance attributes, methods, inheritance, properties, dataclasses, __slots__, and common pitfalls.

pythonobject-oriented programminginheritancedataclasses
A Python code editor showing an object with an attribute being removed using the delattr function, with a subtle warning icon indicating missing attribute handling.
Python

Python delattr: Removing Object Attributes Cleanly

Python's delattr built-in: Learn how to delete object attributes, handle missing attributes, and avoid common pitfalls.

Pythondelattrobject attributesdynamic attributes
A diagram showing Python attribute access interception with __getattribute__.
Python

Python __getattribute__: How to Intercept Attribute Access

Learn how Python's __getattribute__ method controls attribute access, how to override it safely, and when to use it instead of __getattr__.

PythonMagic MethodsAttribute AccessMetaprogramming
Illustration of Python getattr function retrieving an attribute from an object with a fallback default value.
Python

Python getattr: Dynamic Attribute Access Explained

python **getattr**: Learn how Python's getattr() enables dynamic attribute access, handles missing attributes with defaults, and when to use it over direct dot notation.

getattrdynamic attribute accesspython builtinsreflection
Diagram showing a Python class with __slots__ using fixed attribute descriptors instead of a per-instance dictionary.
Python

Python __slots__: Memory Savings and Faster Access

Learn how Python's __slots__ reduces per-instance memory and can speed up attribute access by replacing the instance dictionary with fixed descriptors.

__slots__memory optimizationPython performanceattribute access
Illustration of Python del statement deleting a variable from memory, showing a pointer being removed.
Python

Python del: Deleting Variables, Items, and Attributes

Understand Python's del statement: how to delete variables, list items, dictionary keys, and attributes, and how it affects memory and references.

Pythondel statementmemory managementgarbage collection
Editorial illustration contrasting Python's __new__ method that creates an instance with __init__ that initializes its state.
Python

Python __init__ vs __new__: What Actually Runs

Python object creation runs __new__ before __init__. __new__ creates and returns the instance; __init__ initializes it. See practical examples, edge cases, and when to override __new__.

__new____init__object lifecyclePython internals
Illustration of Python object creation showing the __new__ method allocating an instance before __init__ initializes it.
Python

The Python __new__ Method: Customizing Object Creation

Learn how Python's __new__ method controls object creation, differs from __init__, and supports patterns like singletons and immutable types.

__new__object creationsingleton patternimmutable types