python oop kwargs tutorial code example
Example 1: 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 2: python *args to dict
def func(arg1, arg2, arg3=3, arg4=4):
print(locals())
func(1, 2)
# {'arg3': 3, 'arg4': 4, 'arg1': 1, 'arg2': 2}