Python - Class 11
Python - Class 11
We have to define those statements as a single unit and we can call that
unit any number of times. This unit is nothing but a function.
1. Built in Functions
2. User Defined Functions
1. Built in Functions:
Eg:
id()
type()
input()
eval()
etc..
def function_name(parameters):
Program 1;
def greetings():
print("Hello")
greetings()
greetings()
greetings()
greetings()
greetings()
#Function Type 1:
#Function without arguments and without return type
def add():
a = 10
b = 20
print(a+b)
add()
#Function Type 2:
#Functions with arguments and without return type
def add(a,b):
print(a+b)
add(123,456)
#Function Type 3:
#Functions without arguments and with return type
def add():
a = 100
b = 200
return a+b
result = add()
print(result)
#Function Type 4:
#Functions with arguments and with return type
result = add(23,45)
print(result)
def calculator(a,b):
sum = a+b
diff = a-b
product = a*b
quo = a/b
return sum, diff,product,quo
result = calculator(1234,50)
for i in result:
print(i)
sum()
sum(10,20)
sum(123,456)
sum(10,20,30,40,50)