1def add(*args): # *args takes multiple inputs
2 return sum(args)
3
4
5print(add(1,2,3,4,5)) # prints 15
6print(add(10, 20, 30)) # prints 60
1def calculate(n, **kwargs):
2 print(n + kwargs['add'])
3 print(n * kwargs['multiply'])
4
5
6calculate(3, add=4, multiply=5)
1def multiply(*args):
2 z = 1
3 for num in args:
4 z *= num
5 print(z)
6
7multiply(4, 5)
8multiply(10, 9)
9multiply(2, 3, 4)
10multiply(3, 5, 10, 6)
1>>> def argsKwargs(*args, **kwargs):
2... print(args)
3... print(kwargs)
4...
5>>> argsKwargs('1', 1, 'slgotting.com', upvote='yes', is_true=True, test=1, sufficient_example=True)
6('1', 1, 'slgotting.com')
7{'upvote': 'yes', 'is_true': True, 'test': 1, 'sufficient_example': True}