Inner function
An inner function is a function defined within the body or scope of another function.
Python How-To
A nested function is a function defined within the body of another function.
- How it is used
- Uses inner functions to create callable variants with fixed values and to wrap functions in decorators.
- How deep it goes
- Works through returned functions, enclosing-variable assignment, and decorator wrapper pitfalls; defers a full explanation of closures.
- Examples
- Shows incrementing functions, a decorator wrapper, metadata checks, and contrasting assignments with and without nonlocal.
- What you can do after
- Build it from scratch: return an inner function that uses an enclosing value, or use nonlocal when it must change that value.
F# in Action: A Revised Edition of Get Programming with F#
A nested function is a function defined inside another scope or function.
- How it is used
- Uses inner functions to keep small helper logic private to a larger operation.
- How deep it goes
- Defines nested functions and capturing, while only noting performance implications without further detail.
- Examples
- Demonstrates a local `makeFullName` helper that builds a greeting from first and last names.
- What you can do after
- Apply inner functions to place helper behavior beside the operation that uses it.
Read how F# in Action: A Revised Edition of Get Programming with F# explains inner function →
Get Programming: Learn to code with Python
A function defined within the scope of an enclosing function.
- How it is used
- Explains how to organize task-specific helpers and create specialized functions within an enclosing function.
- How deep it goes
- Defines nesting, scope, returned function objects, and chained execution through small examples and trace exercises.
- Examples
- Uses singing stops, chained message functions, area helpers, student vacation details, and file-data analysis helpers.
- What you can do after
- Build it from scratch by defining task-specific inner functions, calling them within scope, and returning function objects when useful.
Read how Get Programming: Learn to code with Python explains inner function →
Python Workout, Second Edition
An inner function is a function defined within the scope of another function or enclosing code block.
- How it is used
- Uses inner functions to generate multiple specialized password functions from different character strings.
- How deep it goes
- Explains definition timing, returned functions, enclosing-scope access, and LEGB lookup, but stops short of broader closure mechanics.
- Examples
- Demonstrates password generators for alphabetic and symbol character sets, with lengths five and ten.
- What you can do after
- Build it from scratch: define, return, and invoke specialized password generators that retain an outer character set.
Read how Python Workout, Second Edition explains inner function →
Python Workout: 50 ten-minute exercises
An inner function is a function defined within the body of another function.
- How it is used
- Uses inner functions to create reusable password generators with different character restrictions.
- How deep it goes
- Explains definition, creation timing, returned functions, closures, and LEGB lookup, stopping short of broader closure mechanics.
- Examples
- Demonstrates password generators for alphabetic and symbolic character sets, including multiple returned functions and generated outputs.
- What you can do after
- Build reusable function factories that retain configuration from an outer call.
Read how Python Workout: 50 ten-minute exercises explains inner function →
Related concepts
- functionkind of · A function is a callable program unit that performs an operation, may accept inputs, and can produce a result or side effect.
- closureequivalent to · A closure is a function or callable value together with access to bindings from the lexical environment in which it was created.
- enclosing functionpart of · An enclosing function is a function whose body contains a nested function definition and provides a surrounding lexical scope for it.
- scopeuses · Scope is the region of a program in which names are visible and can be resolved according to the language’s lookup rules.
- bindinguses · Name binding is the association of an identifier with the program entity or value it denotes.
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.




