Home | | Problem Solving and Python Programming | Function Prototypes

Python - Function Prototypes | Problem Solving and Python Programming : Data, Expressions, Statements

Chapter: Problem Solving and Python Programming : Data, Expressions, Statements

Function Prototypes

i. Function without arguments and without return type ii. Function with arguments and without return type iii. Function without arguments and with return type iv. Function with arguments and with return type

Function Prototypes:

 

i.                 Function without arguments and without return type

ii.              Function with arguments and without return type

iii.            Function without arguments and with return type

iv.            Function with arguments and with return type

 

i) Function without arguments and without return type

 

o       In this type no argument is passed through the function call and no output is return to main function

o       The sub function will read the input values perform the operation and print the result in the same block

 

ii)           Function with arguments and without return type

 

o       Arguments are passed through the function call but output is not return to the main function

 

iii)        Function without arguments and with return type

 

o       In this type no argument is passed through the function call but output is return to the main function.

 

iv) Function with arguments and with return type

 

In this type arguments are passed through the function call and output is return to the main function

 

Without Return Type

 

Without argument

def add():

a=int(input("enter a"))

b=int(input("enter b"))

c=a+b

print(c)

add()

 

OUTPUT:

enter a 5

enter b 10

15

 

With argument

def add(a,b):

c=a+b

print(c)

a=int(input("enter a"))

b=int(input("enter b"))

add(a,b)

 

OUTPUT:

enter a 5

enter b 10

15

 

With return type

 

Without argument

def add():

a=int(input("enter a"))

b=int(input("enter b"))

c=a+b

return c

c=add()

print(c)

 

OUTPUT:

enter a 5

enter b 10

15

 

With argument

def add(a,b):

c=a+b

return c

a=int(input("enter a"))

b=int(input("enter b"))

c=add(a,b)

print(c)

 

OUTPUT:

enter a 5

enter b 10

15

 


Tags : Python , Problem Solving and Python Programming : Data, Expressions, Statements
Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Problem Solving and Python Programming : Data, Expressions, Statements : Function Prototypes | Python

Related Topics

Problem Solving and Python Programming : Data, Expressions, Statements


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.