Variable-Length Argument Function

Last Updated: 01th September 2025


A function that accepts a variable number of parameters/arguments and stores them in a tuple.

📝 Syntax:

def function_name(*args):
    # function body
    #..
    #..

#When Call it
function_name(argument1, argument2, argument3)

Example 1.

def greet(*names):
    for name in names:
        print(f"Hello, {name}!")

# Calling the function
greet("Avi", "Amit", "Sadhu")

Example 2.

def add(a,b,*args):
    total=a+b
    for i in args:
        total+=i
    print(total)

# Calling the function
add(1,2,3,4,5)

Example 3.

def add(*args,a,b):
    total=a+b
    for i in args:
        total+=i
    print(total)

# Calling the function
add(1,2,3,4,5,a=10,b=20)

💡 Quick Practice