Dictionary of keyword arguments

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

Dictionary of keyword arguments
[Introduction to Udemy Python3 + Application] 53. Dictionary of keyword arguments
Positional arguments, keyword arguments, default arguments
Summary of Python arguments
Other applications of dictionary learning
Keyword arguments for Python functions
Order of arguments of RegularGridInterpolator and interp2d
Expansion by argument of python dictionary
Basic grammar of Python3 system (dictionary)
python> keyword arguments> hoge (** {'a': 1,'b': 2,'c': 3})
About the arguments of the setup function of PyCaret
EP19 Provide Optional Behavior with Keyword Arguments
Expand any number of arguments with yasnippet