Function is a set of code block used to perform certain task repetitively. We can say that if certain work we need to do many time in our code then we can define a function to achieve this.
example below with basic functions defined:
I created a small python program name func1.py and then i called it from my shell:-
Owners-MacBook-Air:python owner$ cat func1.py
def myfirstfunction():
print("My First Function in Python!")
Owners-MacBook-Air:python owner$ python3.7 func1.py
Owners-MacBook-Air:python owner$
as you noticed nothing is given as output, because we have not called the function in our program.
now same python script I will call below again where function is called:-
Owners-MacBook-Air:python owner$ cat func1.py
def myfirstfunction():
print("My First Function in Python!")
myfirstfunction()
Owners-MacBook-Air:python owner$ python3.7 func1.py
My First Function in Python!
Owners-MacBook-Air:python owner$