An inner function is defined inside an outer function and can be returned as a callable object. It retains access to variables from the enclosing invocation. section 7.11
Use inner functions when each outer invocation should create a specialized callable:
- Pass configuration to the outer function, such as an allowed-character string. section 7.10
- Define the inner function during the outer function’s execution. section 7.11
- Return the inner function and call it later with its own argument. section 7.10
Password generators
Calling create_password_generator with different character strings produces independent functions, such as alphabetic and symbol generators, each accepting a requested length. section 7.10 section 7.11
alpha_password = create_password_generator('abcdef')
symbol_password = create_password_generator('!@#$%')
print(alpha_password(5)) # efeaa
print(alpha_password(10)) # cacdacbada
print(symbol_password(5)) # %#@%@
print(symbol_password(10)) # @!%%$%$%%#
Inspect executable calls that create separate alphabetic and symbol password functions and invoke them at different lengths. section 7.10




