Python program for passing multiple arguments to a function

Here, we will write a Python program in which we will pass multiple arguments to the function. By Shivang Yadav Last updated : January 05, 2024

Functions in Python are very important as they reduce the number of lines of code.

Python allows its users to pass more than one argument to the function.

This is done using * notation,

Syntax

def function_name (* arguments)

Program for passing multiple arguments to a function

# Python program for passing 
# multiple arguments to a function

# python program to find sum of any number 
# of arguments passed to it
def findSum(*data):
    sumVal = 0
    for item in data:
       sumVal += item
    print("Sum of all arguments is ",sumVal)

# Calling function with variables...  
findSum()
findSum(12)
findSum(12,4)
findSum(12,4,6)
findSum(1,2,3,4,5,6,7,8)
findSum(12,45,67,78,90,56)

Output

The output of the above example is:

Sum of all arguments is  0
Sum of all arguments is  12
Sum of all arguments is  16
Sum of all arguments is  22
Sum of all arguments is  36
Sum of all arguments is  348

To understand the above program, you should have the basic knowledge of the following Python topics:

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





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