A function is a block of code which only runs when it is called. You can pass data, known as parameters, into a function. A function can return data as a result.
Function is divided mainly into 2 parts in python:
FUNCTION DEFINITION IN PYTHON
In Python a function is defined using the def keyword. The syntax of function definition is:
def name(): print("hello world")
FUNCTION CALLING IN PYTHON
In this, we can call a function name which we define it earlier. To call a function, use the function name followed by parenthesis. The syntax is:
def name(): print("hello world") name()
After calling a function, it starts performing its task which is assigned to it.
PARAMETERIZED FUNCTION IN PYTHON
In this, we can pass parameters through function. Information can be passed to functions as parameter. Parameters are specified after the function name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma.
The syntax is:
def fname(name): print(name + " Sharma") fname("Divya") fname("Armaan")