Types of Function in Python

Types of Function in Python

Types of Function in Python

Type 1: Function not returning a value and no parameter passing

def add():

               n1 = int(input(“Enter first number:”))

              n2 = int(input(“Enter second number: “))

             s = n1+ n2

            print(“Addition:“, s)

add()

Output

Enter first number: 12

Enter second number: 23

Addition: 35 

Type 2: Function not returning a value but parameter passing

def add(n1, n2):

                 n1 + n2

               print(“Addition:“s)

n1 = int(input(“Enter first number:” ))

n2 = int ( input ( ” Enter second number : ” ) )

add(n1, n2)

Output

Enter first number: 12

Enter second number: 23

Addition: 35

Type 3: Function returning a value but no parameter passing

def add( ) :

              n1= int(input(“Enter first number:“)

             n2 = int(input(“Enter second number: “)

            s = n1 + n2

          return s

s = add()

print( “Addition:“s)

Output

Enter first number: 12

Enter second number: 23

Addition: 35

Type 4: Function returning a value and parameter passing

def add(n1, n2):

                   s=n1+n2

                  return s

n1= int(“input Enter first number: “))

n2= int(input( “Enter second number: “))

s= add(n1, n2)

print( “Addition:“, s)

Output

Enter first number: 12

Enter second number: 23

Addition: 35

Leave a Reply

Your email address will not be published. Required fields are marked *