You use functions in programming to bundle a set of instructions that you want to use repeatedly.That means that a function is a piece of code written to carry out a specified task.
There are three type of Function in python -
- Build -In function such as print(),input(),min() etc.
- User defined function
- Anonymous functions, which are also called lambda functions
So for create user defined function , in C language to make a function we need to declare the type of function, but in python we have only one keyword for create the function which is 'def'
Syntax :-
def functionname():
body
Program-
def hii():
print("Hii")
def hello():
print("Hello")
def value(a):
print(a)
hii()
hello()
value(3)
value("Pass")
Hii
Hello
3
Pass
In this program, there are three function, 'hii()', 'hello()' and 'value(a)' , first two function are normal they print hii hello, while third function require parameter to pass , so at the time of calling we pass value in it so it can save in 'a' and then we print(a)