What are Functions?
Functions are a convenient way to divide your code into useful blocks, allowing us to order our code, make it more readable, reuse it.
Here are simple rules to define a function in Python –
- Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).
- Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses.
- The code block within every function starts with a colon (:) and is indented.
- The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None.
- The first statement of a function can be an optional statement – the documentation string of the function or docstring.
- All parameters (arguments) in the Python language are passed by reference.
- The return statement is used to return from a function i.e. break out of the function.
- Every function implicitly contains a return None statement.
- Python supports multiple returns.