Functions Flashcards
Arguments
positional *args
keyword **kwargs
variable-length (varargs):
*args, **kwargs
actual parameters
Parameters
(pos, /, pos_or_kw, *, kw)
required
optional
formal parameters
PEP 570
Parameters order
non-default parameters, default parameters
Arguments order
positional, keyword
Lambda
bound variable
single expression
no type annotations
argument to higher-order function
Global Scope
global variable
global keyword
module scope
global variables are available from any scope except built-in
Local Scope
declared inside function
available within the function
Nonlocal Variable
nonlocal keyword
used in nested functions
defined in an outer (enclosing) scope but not in the global scope
Enclosing Scope
scope of outer function
nonlocal scope
Built-in Scope
special reserved keywords
__builtins__ module
LEGB
Local
Enclosing
Global
Built-in
First-Class Function
- assign to variable
- pass as an argument
- return from function
first-class citizen
Higher-Order Function
a function that can take other functions as arguments or return functions as results
map, filter
Free Variable
variable that is used in a code block but not defined there
in closure defined in enclosing scope
can be global if the nearest enclosing scope contains a global statement
can be nonlocal
Closure
function that retains access to variables from the enclosing scope even after the outer function has finished executing
function.__closure__
closure factory