How to use variable-length arguments in python function

Author: Al-mamun Sarkar Date: 2020-03-25 08:51:22

How to use variable-length arguments in python function. The following code shows how to use variable-length arguments in the Python programing language.

def add(*args):
    print(type(args))
    temp = 0
    for i in args:
        temp += i
    return temp


print (add(1, 5, 45, 25, 12, 3))


def add(**kwargs):
    print(type(kwargs))
    tmp = 0
    for key in kwargs:
        tmp = tmp + kwargs[key]
    return tmp


temp = add(a=1, b=2, c=3, d=4)
print(temp)

 

Output:


91

10