liveBook · Manning

Enclosing function

Also called outer function

An enclosing function is a function whose body contains a nested function definition and provides a surrounding lexical scope for it.

How 2 Manning books explain it

Python Workout, Second Edition

An enclosing function is a function whose scope contains the definition or execution context of a nested function.

How it is used
Uses nested functions to retain invocation-specific configuration and state in returned callable objects.
How deep it goes
Explains nested-function creation, LEGB lookup, and nonlocal updates, stopping short of broader closure internals.
Examples
Demonstrates password generators, multiplication factories, call counters, shadowed built-ins, and local-versus-global names.
What you can do after
Build it from scratch using nested functions that retain configuration or update enclosing state with nonlocal.

Read how Python Workout, Second Edition explains enclosing function →

Python Workout: 50 ten-minute exercises

An enclosing function is a lexically surrounding function whose local bindings can be accessed by a nested function.

How it is used
Uses nested functions to return configurable behavior that retains values from an earlier function invocation.
How deep it goes
Explains LEGB lookup, closure creation, separate retained bindings, and nonlocal updates through runnable examples.
Examples
Demonstrates password generators, a returned multiplier, a persistent call counter, and shadowed names.
What you can do after
Apply it via Python to build returned functions that retain configuration or mutable state across calls.

Read how Python Workout: 50 ten-minute exercises explains enclosing function →

Also covered in

What to know first

Related concepts

Questions about enclosing function

What is enclosing function?

An enclosing function is a function whose body contains a nested function definition and provides a surrounding lexical scope for it.

Which Manning books explain enclosing function?

Python Workout, Second Edition and Python Workout: 50 ten-minute exercises.

What should I know before learning enclosing function?

Manning books that teach enclosing function usually introduce function declaration, password authentication and scope first.

What is enclosing function a kind of?

Enclosing function is a kind of function. A function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.

What is enclosing function part of?

Enclosing function is part of scope. Scope is the region of a program in which names are visible and can be resolved to their bindings according to the language’s rules.

What are the parts of enclosing function?

Enclosing function includes inner function.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.