A function is a block code that takes in some data and, either performs some kind of transformation and returns the transformed data, or performs some task on the data, or both.
Parts of function:–
- Keyword def- This is the keyword used to say that a function will be defined now.
- Function name- This is the name that is used to identify the function. The function name comes after the def keyword.
If the function name has multiple words, they should be in lower case, and they should be separated with an underscore.
- Parameter list- Parameter list are placeholder that define the parameters that go into the function. In python, parameters are enclosed in parentheses.
- Function docstring- These are optional constructs that provide a convenient way for associated documentation to the corresponding function. Docstring are enclosed by triple quotes.
- Function returns- Python function returns a value.
def name_of_function(arguments): ''' docstring ''' body of function return
Note that the function block is intended by four spaces.