Define Function:
Collection of code which performs a specific task. Definition Function starts with ‘def’.
Function is very commonly used coding technique in Python. In real time scenarios, the python application (or) python data pipeline is developed using one or more python Functions.
Example:
Code:
def name_age(name, age):
===>print("You are " + name + " at age " + age)
name_age("John", "30")
Result:
You are John at age 30
Define Function with Return:
When there is a need to get a value back from Function, the ‘return’ statement helps to get that value from the Function.
‘return’ is the last statement to be used in the ‘Function’ because the control exits out of Function after return statement.
Example:
Code:
def cube(num):
===>return num*num*num
result = cube(5)
print(result)
Result:
125