A user-defined function is a named sequence of statements that perform a computation.
Functions provide benefits as they
Functions are defined once with the def
statement. Then, they may be called many times with the call operator ()
.
They may process parameterized inputs, passed in as arguments, and output a return value.
Arguments may be passed in by position or keyword. Some functions may even require keyword-only arguments.
Lambda expressions create anonymous functions.
Functions are a special kind of callables. Any object that may be called with the call operator ()
is a callable. Built-in functions and constructors are other kinds of callables.
Core Python can be extended with code from either the standard library or third-party libraries.
Outside Jupyter notebooks, Python code is put into modules that are grouped in packages.