0
3

More than 3 years have passed since last update.

位置引数とタプル化と辞書化の混在

Posted at
def players(job, *args, **kwargs):
    print(job)
    print(args)
    print(kwargs)

players('勇者', '戦士', '魔法使い', job1='僧侶', job2='魔法剣士')
実行結果
勇者
('戦士', '魔法使い')
{'job1': '僧侶', 'job2': '魔法剣士'}

jobに'勇者'が
argsに('戦士', '魔法使い')がタプル型で
kwargsに{'job1': '僧侶', 'job2': '魔法剣士'}と辞書型で
格納されている。

ただし、
*1つが*2つよりも先でないと、
syntax errorとなるので注意。

0
3
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
0
3