Python | Function classifications on the basis of parameters and return values

Python function classifications: Here, we are going to learn about the Python function classifications based on their parameters and return values. By Pankaj Singh Last updated : December 30, 2023

There are following types of the Python functions based on their parameters and return values:

  1. Function with no argument and no return value
  2. Function with no argument but return value
  3. Function with argument and no return value
  4. Function with arguments and return value

1) Function with no argument and no return value

These types of Python functions do not take any argument and do not return any value.

def sum():
    a = int(input("Enter A: "))
    b = int(input("Enter B: "))
    c=a+b
    print("Sum    :", c)

def main():
    sum()

if __name__=="__main__":
    main()

Output

Enter A: 10
Enter B: 20
Sum    : 30

2) Function with no argument but return value

These types of Python functions do not take any argument but return a value.

def sum():
    a = int(input("Enter A: "))
    b = int(input("Enter B: "))
    c=a+b
    return c

def main():
    c = sum()
    print("Sum    :",c)

if __name__=="__main__":
    main()

Output

Enter A: 10
Enter B: 20
Sum    : 30

3) Function with argument and no return value

These types of Python functions have the arguments but do not return any value.

def sum(a,b):
    c=a+b
    print("Sum    :", c)

def main():
    a = int(input("Enter A: "))
    b = int(input("Enter B: "))
    sum(a,b)

if __name__=="__main__":
    main()

Output

Enter A: 10
Enter B: 20
Sum    : 30

4) Function with arguments and return value

These types of Python functions have the arguments and also return a value.

def sum(a,b):
    c=a+b
    return c

def main():
    a = int(input("Enter A: "))
    b = int(input("Enter B: "))
    c = sum(a,b)
    print("Sum    :",c)

if __name__=="__main__":
    main()

Output

Enter A: 10
Enter B: 20
Sum    : 30

Python Tutorial

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.