Python guides
Every published Python guide, newest first, with practical examples you can copy into your own project.
3,965 guides across 14 topics
Topics
Popular Python guides
Most readLatest Python guides
Page 130 of 179Returning 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.
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.
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.
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.
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.
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.
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.
Python Inner Function: Syntax, Scope, and Use Cases
Understand python inner function syntax, closure behavior, and practical uses like decorators and factory functions.
Python Nested Function: Scope, Closures, and Use Cases
Understand how nested function scope works in Python, how closures capture variables, and when inner functions improve code structure.
Python Recursion Limit: Setting and Handling Deep Recursion
python recursion limit: Understand Python's recursion limit, how to check and adjust it, and why iterative alternatives are often safer for deep recursion.