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}
1# We use *args and **kwargs as an argument when we are unsure
2# about the number of arguments to pass in the functions.
3
4#This is an example of *args
5def adder(*num):
6 sum = 0
7
8 for n in num:
9 sum = sum + n
10
11 print("Sum:",sum)
12
13adder(3,5)
14adder(4,5,6,7)
15adder(1,2,3,5,6)\
16
17
18#This is an example of **kwargs
19def intro(**data):
20 print("\nData type of argument:",type(data))
21
22 for key, value in data.items():
23 print("{} is {}".format(key,value))
24
25intro(Firstname="Sita", Lastname="Sharma", Age=22, Phone=1234567890)
26intro(Firstname="John", Lastname="Wood", Email="johnwood@nomail.com", Country="Wakanda", Age=25, Phone=9876543210)