Browse by Topic

Popular

Latest

Latest Python Posts

Illustration showing a function being passed as an argument and invoked by another function in Python
Python

Python Callback Function: Passing Functions as Arguments

Learn how Python callback functions work, how to pass functions as arguments, handle errors, and choose the right pattern for your code.

callbackshigher-order functionsfunction argumentsevent handling
Illustration of a Python higher order function passing a function into another function as an argument
Python

Python Higher Order Functions Explained with Examples

Learn how to use Python higher order functions to write cleaner, reusable code with map, filter, reduce, decorators, and closures.

higher-order functionsmap filter reducedecoratorsclosures
Illustration of a Python function returning another function, representing closures and factories.
Python

Returning Functions in Python: Closures and Factories

Learn how to return functions in Python, how closures capture state, when to use factory functions, and how to avoid common closure pitfalls.

closuresdecoratorsfunction factorieshigher-order functions
A visual metaphor of a Python function being passed as an argument to another function, representing higher-order functions.
Python

Python Function as Argument: Patterns and Pitfalls

Learn how to pass a Python function as an argument, including callbacks, higher-order functions, lambdas, and common mistakes.

higher-order functionscallbackslambdafunction arguments
Illustration of Python functions being passed as arguments and returned from functions, showing first-class function behavior.
Python

Python First-Class Functions in Practice

Learn how Python treats functions as first-class objects: pass them, return them, store them, and use them in higher-order functions and decorators.

higher-order functionsclosuresdecoratorsfunctional programming
Diagram showing a nested function referencing a variable from an enclosing function via the nonlocal keyword.
Python

Python nonlocal in Closures: Scope Rules

Understand how Python's nonlocal keyword works in closures: when assignment must rebind an enclosing variable, how it differs from global and local scopes, and how to use it to manage state.

closuresvariable scopenested functionsnonlocal keyword
Diagram showing a Python closure capturing a variable from an outer function, with arrows indicating the reference to the variable cell.
Python

Python Closure Variable Capture Explained

See how Python closures capture variables, why late binding returns the final loop value, and how to control captured values with default arguments and nonlocal.

closuresvariable scopenonlocallate binding
Illustration of a Python closure capturing a variable from an outer function's scope.
Python

Python Closures: How Nested Functions Capture State

Learn how Python closures capture variables from enclosing scopes, how nonlocal modifies captured state, and when a closure is the right tool compared with classes and lambdas.

closuresnested functionsnonlocalfunction factories
Diagram illustrating Python function scope with nested functions and variable lookup order.
Python

Python Function Scope: Local, Global, and Nonlocal

Understand how Python function scope resolves variable names inside functions with the LEGB rule, and learn when to use global, nonlocal, and closures.

pythonscopeclosuresLEGB
Diagram of an outer function containing a nested inner function with a closure arrow showing captured state
Python

Python Inner Function: Syntax, Scope, and Use Cases

Understand python inner function syntax, closure behavior, and practical uses like decorators and factory functions.

nested functionsclosuresdecoratorsnonlocal