ADVERTISEMENT
ADVERTISEMENT

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.
Submitted by Shivang Yadav, on March 22, 2021

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:

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

Python Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.