Module -4(function)

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 12

Module -4

Function
Content
• Defining a Function
• Calling a Function
• Default Attribute Function
Function
function is a block of code which is used to perform particular task.
There are two types of function:-
1 Library or Inbuilt function
for example:-
print(),sum(),input() etc.
2 user defined function
There are four types of user defined function:-
User defined function
• There are four types of user defined function:-
1 No Argument No Return Type
2 With Argument No Return Type
3 No Argument with Return Type
4 With Argument with Return Type.
Declearation of function
• Syntax:-
def function_name(): // function declearation
Block of code
Function_name()// function calling

• def keyboard is used to we can defined a function.


example
def greet():
g=input("Enter Your Greet!!!!")
print(g)
greet()
greet()
greet()
greet()
1 No Argument No Return Type

# addition of two numbers:-


def add():
n1=int(input("Enter the first number:-"))
n2=int(input("Enter the second number:-"))
add=n1+n2
print("Addition of ",n1,"+",n2,"=",add)
add()
2 With Argument No Return Type

x=int(input("Enter the first number"))


y=int(input("Enter the second number:-"))
def sub(a,b):
sub=a-b
print("substraction is ",sub)
sub(x,y)
3 No Argument with Return Type

def mult():
n1=20
n2=10
multiply=n1*n2
return multiply
print("multiplication is :-",mult())
With Argument With Return Type
division of two numbers:
def div(a,b):
Div=a//b
return Div
z=div(20,10)
print(“division is ”,z)
Default Attribute Function

• The following example shows how to use a default parameter value.


If we call the function without argument, it uses the default value:

def my_function(country = “India"):


print("I am from " + country)

my_function("Sweden")
my_function(“Norway")
my_function()
my_function("Brazil")
Thank you

You might also like