kwargs.py
#When using args and kwargs together, be careful in order
def say_dic(word, *args, **kwargs):
print(word)
print(args)
print(kwargs)
for k, v in kwargs.items():
print(k,v)
say_dic('hello', 'Mike',1, desert='banana', drink='beer')
#How to pass after making a dictionary
t = {'math':15, 'science':100}
say_dic('hi', 'Nancy', 2, **t)
Output result:
hello
('Mike', 1)
{'desert': 'banana', 'drink': 'beer'}
desert banana
drink beer
hi
('Nancy', 2)
{'math': 15, 'science': 100}
math 15
science 100
Recommended Posts