1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

キーワード引数の辞書化

Last updated at Posted at 2020-02-13
kwargs.py
#argsとkwargsを併用する場合は、順番に注意
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')

t = {'math':15, 'science':100}
#辞書を渡す場合は、**をつけて渡す
say_dic('hi', 'Nancy', 2, **t)

出力結果:

hello
('Mike', 1)
{'desert': 'banana', 'drink': 'beer'}
desert banana
drink beer
hi
('Nancy', 2)
{'math': 15, 'science': 100}
math 15
science 100
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?