with A() as a: with B() as b: SUITE @f1 (arg) @f2 def func(): pass def func(): pass func=f1(arg)(f2(func)) except that the original function is not temporarily bound to the name$_{func}$ . is roughly equivalent to 2 A string literal appearing as the first statement in the function body is transformed into the function’s __doc__ attribute and therefore the function’s docstring . Chapter 8. Compound statements 100 A function definition may be wrapped by one or more decorator expressions. Decorator expressions are evaluated when the function is defined, in the scope that contains the function definition. The result must be a callable, which is invoked with the function object as the only argument. The returned value is bound to the function name instead of the function object. Multiple decorators are applied in nested fashion. For example, the following code The function definition does not execute the function body; this gets executed only when the function is called. 2 A function definition is an executable statement. Its execution binds the function name in the current local namespace to a function object (a wrapper around the executable code for the function). This function object contains a reference to the current global namespace as the global namespace to be used when the function is called. PEP 343 - The “with” statement The specification, background, and examples for the Python with statement. See also: Changed in version 3.1: Support for multiple context expressions. is semantically equivalent to: With more than one item, the context managers are processed as if multiple$_{with}$ statements were nested: The Python Language Reference, Release 3.9.5 with A() as a, B() as b: SUITE A function definition defines a user-defined function object (see section The standard type hierarchy ): 8.6 Function definitions funcdef ::= [ decorators ] "def" funcname "(" [ parameter_list ] ")" ["->" expression ] ":" suite decorators ::= decorator + decorator ::= "@" assignment_expression NEWLINE parameter_list ::= defparameter ("," defparameter | parameter_list_no_posonly parameter_list_no_posonly ::= defparameter ("," defparameter )* ["," [ | parameter_list_starargs parameter_list_starargs ::= "*" [ parameter ] ("," defparameter )* ["," ["**" | "**" parameter [","] parameter ::= identifier [":" expression ] defparameter ::= parameter ["=" expression ] funcname ::= identifier