-
Notifications
You must be signed in to change notification settings - Fork 0
Functions
A series of statements which returns some value to a caller. It can also be passed zero or more arguments which may be used in the execution of the body. See also parameter, method, and the Function definitions section.
-- Python docs
All functions calls return one object, although that object might be None (signifying no value) or a tuple containing multiple elements (signifying multiple values).
If there is no return statement, or just a bare return, the object returned is None.
Sometimes, it's correct to return multiple values from a function. For this, you can return a tuple of values.
Variadic Arguments
So far, we've seen that arguments can be supplied either by position or by name, and that arguments are matched to named parameters (which might have default values) from the function signature when the function is invoked. What happens if we want to capture an argument that we don't expect?
Variadic parameters are Python's answer to that question. A variadic parameter collection collects excess arguments (that would otherwise go unmatched to a parameter) into a data structure, for the function implementation's use. We'll see two kinds of variadic parameters: variadic positional parameters and variadic keyword parameters.
https://docs.python.org/3/tutorial/controlflow.html#defining-functions https://realpython.com/python-return-statement/