Browse by Topic

Popular

Latest

Latest Posts

Illustration of a Python function dispatching to different type-specific implementations based on the first argument's type.
Python

Python Single Dispatch: Type-Based Function Overloading

Learn how Python's functools.singledispatch replaces isinstance chains with registered type-specific handlers for type-based function overloading.

functoolsgeneric functionstype dispatchpolymorphism
Illustration of a Python generic function dispatching to different implementations based on the runtime type of the first argument.
Python

Using python singledispatch for Clean Type-Based Dispatch

Learn how Python's functools.singledispatch enables clean type-based dispatch: registration patterns, inheritance and ABC behavior, performance characteristics, and practical examples.

functoolsgeneric functionstype dispatchPython decorators
A Python function wrapped by a cache decorator storing results in a memory cache.
Python

Python Cache Decorator: How to Cache Function Results

Learn how to use a Python cache decorator to store function results, avoid repeated computation, and manage memory limits and concurrency.

cachingdecoratorsfunctoolsmemoization
A stylized cache memory block with an LRU eviction queue, representing Python's lru_cache decorator for memoization.
Python

python lru_cache: Efficient Memoization

Learn how to use python lru_cache to memoize function results, manage cache size, handle unhashable arguments, and avoid common pitfalls.

lru_cachememoizationfunctoolscaching
Illustration of a Python function wrapped by an LRU cache decorator showing cached results being reused for repeated calls.
Python

Python functools.lru_cache: Caching Function Results

Learn how to use Python's functools.lru_cache to memoize function results, manage cache size with maxsize, and avoid common pitfalls in real applications.

lru_cachefunctoolsmemoizationcaching
Illustration of a Python partial function binding arguments to a callable object, showing a function symbol with pre-bound parameters.
Python

Python Partial Function: Pre-Bind Arguments

python partial function: Learn how to use functools.partial to pre-bind arguments and create specialized callables in Python, with practical examples and common pitfalls.

functools.partialfunctional programmingargument bindingcallable objects
A diagram showing a function with pre-filled arguments being wrapped by functools.partial to create a new callable.
Python

Python functools.partial: Pre-Filling Arguments for Cleaner Code

Learn how Python's functools.partial pre-fills function arguments, with examples for callbacks, sorting keys, and API wrappers, plus a comparison with lambdas.

functoolspartialfunctional programmingcallbacks
Illustration of Python functools module with partial, cache, and decorator symbols
Python

Using python functools for Cleaner, Faster Code

python functools: Explore the functools module: partial, lru_cache, wraps, reduce, and singledispatch, with practical examples and performance tradeoffs.

functoolshigher-order functionsmemoizationdecorators
Illustration of a Python lambda closure capturing a loop variable by reference, showing the late binding trap.
Python

Python Lambda Late Binding: The Loop Trap

Learn why Python lambdas in loops capture the loop variable by reference, and how to fix late binding with default arguments or functools.partial.

lambdaclosuresscopepython
Diagram showing a closure capturing a loop variable late, with a binding arrow pointing to the final value.
Python

Python Late Binding Closure: How It Works

Understand why Python closures capture variables late and how to bind the correct value in loops and lambdas.

closureslate bindingPython scopinglambda