Browse by Topic

Popular

Latest

Latest Python Posts

Illustration of a Python class instance being invoked with parentheses, showing the __call__ method concept.
Python

Python __call__: Making Objects Callable

python **call**: Learn how Python __call__ makes objects callable like functions, with practical examples covering callbacks, decorators, and stateful callables.

__call__callable objectsdunder methodsPython data model
Illustration of Python next() function retrieving the next item from an iterator chain.
Python

Python next(): Getting the Next Item from an Iterator

Learn how to use Python's next() to fetch the next item from iterators and generators, handle StopIteration, and work with streaming data.

iteratorsgeneratorsbuilt-in functionsStopIteration
Illustration of Python membership testing with the in operator across lists, sets, and dictionaries, showing a magnifying glass and a checkmark.
Python

Python Contains: Membership Testing with the in Operator

Learn how Python's in operator checks membership across lists, strings, sets, and dictionaries, including performance tradeoffs and common pitfalls.

pythonmembership testingin operatordata structures
Illustration of a Python class with __delitem__ method removing a key from a dictionary-like container.
Python

Implementing __delitem__ in Python

Learn how to implement Python's __delitem__ special method so custom classes support del obj[key], handle missing keys, and stay consistent with __getitem__ and __setitem__.

Python__delitem__Special MethodsData Model
Illustration of Python __setitem__ method controlling assignment to a custom container object.
Python

Python __setitem__: Implementing Item Assignment

python **setitem**: Learn how to implement __setitem__ in Python to control item assignment for custom classes, with practical examples and edge cases.

__setitem__dunder methodscustom containersitem assignment
Illustration of a Python object with a square bracket key, representing the __getitem__ method for custom container access.
Python

Python __getitem__: Implementing Custom Container Access

Learn how Python's __getitem__ method powers obj[key] for custom containers: handle slices, raise correct exceptions, and avoid common edge cases.

pythondunder methodscontainersubscription
Illustration of a Python len() function applied to a list showing a constant-time length retrieval.
Python

Python len() Explained: Behavior and Performance

Understand how Python's len() works across built-in types, why it is O(1) for built-in containers, and how to support it in custom classes.

len functionPython built-instime complexity__len__ method
Comparison of Python __str__ and __repr__ methods showing different output for the same object.
Python

Python __str__ vs __repr__: What's the Difference?

Understand the difference between Python's __str__ and __repr__ methods, when to implement each, and how they affect debugging and user-facing display.

Python__str____repr__Debugging
Illustration contrasting a precise, unambiguous __repr__ string with a human-readable __str__ string for a Python object
Python

Python repr: The __repr__ Method Explained

python **repr**: Learn how to implement Python's __repr__ method to produce unambiguous, developer-friendly object representations for debugging and logging.

Python__repr__debuggingobject representation
Illustration of Python str type with Unicode characters and a performance graph.
Python

Working with Python str: Methods, Performance, and Pitfalls

python **str**: Learn how Python's str type works: immutable Unicode text, common methods, formatting, performance tradeoffs, and pitfalls.

Python stringsstr methodsString formattingPerformance