Python Functions

Python Functions and Methods

A function is a block of code that is named (the name of the function), and which allows that block to be called elsewhere in a program by calling the name of the function.

Python Function Default Values

Functions can have parameters with default values. For certain functions, the default value is the most common value for a parameter and is only changed for a specific reason. This makes the code calling the function more readable and removes having to provide the "usual" value as a parameter. Another advantage is that if you change the default value, it affects all the code that uses the default.  

Recursive Functions in Python

Functions can call themselves! This is really handy, but can be really dangerous too, because a function can call itself forever, locking the process, or use up the available memory, reslting in the program crashing.

Python Lambda functions

A lambda function is a (usually small) function that is defined without a name. A lambda function is declared as an expression and then either assigned to a variable or passed as a parameter to another function.