python function undefined number of arguments code example

Example 1: unlimited arguments python

def add(*args):		# *args takes multiple inputs
  return sum(args)


print(add(1,2,3,4,5))    # prints 15
print(add(10, 20, 30))	 # prints 60

Example 2: variable number of arguments to python class

def multiply(*args):
    z = 1
    for num in args:
        z *= num
    print(z)

multiply(4, 5)
multiply(10, 9)
multiply(2, 3, 4)
multiply(3, 5, 10, 6)

Example 3: **kwargs

When it iterating over a dictionary you are only able to iterate over 
the keys not the values. The ** when placed before a variable will allow
you to iterate and unpack both key and value pairs. Because you are 
unpacking both key and value this will return the result as a dictionary.