Browse by Topic

Popular

Latest

Latest Python Posts

Illustration of a python custom iterator showing a sequence of values being produced one at a time through the iterator protocol.
Python

How to Build a Python Custom Iterator

Learn how to implement a Python custom iterator using __iter__ and __next__, when to return self, and when a generator is the simpler choice.

iterator protocolgeneratorslazy evaluationiterables
Illustration of a Python iterator protocol showing a loop with next() calls.
Python

Understanding the Python Iterator Protocol

Learn how the Python iterator protocol works, how to implement custom iterators, and when generators are a better choice.

pythoniteratoriterablegenerators
Diagram showing Python iterable as a box containing items and iterator as a pointer moving through them, illustrating lazy evaluation.
Python

Python Iterable vs Iterator

Learn the difference between Python iterables and iterators, how the iterator protocol works, and when to use each for efficient code.

PythonIterablesIteratorsGenerators
Python iterator protocol illustration showing a sequence of items being consumed one by one from an iterable container.
Python

Python Iterator Protocol and Custom Iterators

Learn how Python iterators work, how to implement custom iterators, and when to use them for memory-efficient lazy evaluation.

PythonIteratorsIterablesGenerators
Illustration of a Python iterable object feeding items into a for loop
Python

Python Iterable: The Iteration Protocol Explained

Learn what makes an object iterable in Python, how the iteration protocol works, and how to build custom iterables with classes and generators.

PythonIteratorsGeneratorsIteration Protocol
Illustration of python nullcontext as a placeholder context manager that does nothing, with a lock and a simple with statement.
Python

Python nullcontext for Optional Context Managers

Understand Python nullcontext and how it helps you write cleaner code when a context manager is optional, with examples and runtime considerations.

Pythoncontextlibcontext managernullcontext
Diagram of a Python context manager closing a resource like a file or network connection.
Python

Python Closing Context Manager: Cleanup Patterns

Learn how contextlib.closing wraps any object that has a close() method so Python's with statement can handle resource cleanup reliably.

contextlibwith statementresource cleanupcontext manager
Illustration of a Python context manager acting as a shield that deflects one specific exception while other exceptions pass through.
Python

Suppressing Exceptions in Python with contextlib.suppress

Learn how to use contextlib.suppress in Python to ignore expected exceptions, pass multiple exception types, and decide when try/except gives you more control.

Pythoncontextlibexception handlingcontext managers
Illustration of multiple context managers in Python being entered and exited in a stack-like order
Python

Python Multiple With Statements: Combining Context Managers

Learn how to combine multiple with statements in Python, control cleanup order, handle exceptions, and choose between flat, nested, or ExitStack-based code.

context managerswith statementresource managementPython syntax
Illustration of nested context managers in Python showing resource acquisition and release order.
Python

Python Nested Context Managers: Syntax and Exit Order

Learn how to nest context managers in Python: syntax, LIFO exit order, exception propagation, and using ExitStack for dynamic resource sets.

PythonContext Managerswith StatementResource Management