FUNCTION
IN
PYTHON
FUNCTION
Function is a group of related statements that perform a specific
task.
A function is block of code which only runs when it is called.
Function help break our program into smaller and modular chunks.
As our program grows larger and larger, function make it
organized and manageable.
It avoids repetition and makes code reusable.
FUNCTION
Built-in function – function that are built into python.
User-defined / Programmer-defined function – function defined by
the users themselves.
CREATING A FUNCTION
In Python a function is defined using the “def” keyword.
A function name to uniquely identify it.
Parameters (arguments) through which we pass values to a function. They
are optional. Any input parameters or arguments should be placed within
parentheses.
A colon (:) to mark the end of function header.
Optional documentation string (docstring) to describe what function does.
Statements must have same indentation level (usually 4 spaces).
An optional “return” statements to return a value from the function.
CREATING A FUNCTION
PARAMETERS (arguments)
Information can be passed to function as parameter.
Parameters are specified after the function name, inside the
parenthesis.
You can add as many parameters as you want, just separate
them with comma.
PARAMETERS (arguments)