Designing functions with optional parameters
When we define a function, we often have a need for optional parameters. This allows us to write functions that are more flexible and easier to read.
We can also think of this as a way to create a family of closely-related functions. We can think of each function as having a slightly different collection of parameters – called the signature – but all sharing the same simple name. This is sometimes called an "overloaded" function. Within the typing module, an @overload decorator can help create type hints in very complex cases.
An example of an optional parameter is the built-in int() function. This function has two signatures:
int(str): For example, the value ofint('355')has a value of355. In this case, we did not provide a value for the optional base parameter; the default value of10was used.int(str, base): For example, the value ofint('163', 16)is355. In...