Python Functions

In Python, a function is a block of organized and reusable code that performs a single specific and well-defined task. Python enables its programmers to break up a program into functions, each of which can be written more or less independently of the others.

Function Definition :

1. Function definition is a declaration statement that identifies a function with its name, a list of arguments that it accepts and the type of data it returns.
2. A function definition consists of a function header that identifies a function, it is followed by the body of the function containing the executable code for that function.
3. A function f that uses another function g, then f is known as a calling function and g is known as a called function.
4. The inputs that the function takes are called arguments/parameters.
5. Function blocks starts with the keyword def.
6. The keyword is followed by the function name and parenthesis().
7. After the parentheses, a colon (:) is placed. The function name is used to uniquely identify the function.
8. Parameters or arguments that the function accepts are placed within parenthesis. Through these parameters values are passed to the function. They are optional. In case of no values are to be passed, nothing is placed within the parenthesis.
9. The first statement of a function can be an optional statement – the documentation string of the function or docstring describes what the function does.
10. The code block within the function is properly intended to form the block code.
11. A function may have a return[expression] statement. That is, the return statement is optional if it exists. it passes back an expression to the caller. A return statement with no arguments is the same as a return of None.
12. You can assign the function name to a variable. Doing this will allow you to call the same function using the name of that variable.