If you don't know how many arguments * args variadic arguments are It was a tuple, Convert keyword arguments into a dictionary and perform the same processing.
dictionary
def players(**kwargs):
for k, v in kwargs.items():
print(k + 'Is' + v + 'is.')
d = {
'Taro':'Brave',
'Jiro':'Warrior',
'Saburo':'Wizard',
'Shiro':'Monk'
}
players(**d)
As before, dictionary d Expand with ** d, Pass it to the players function. ** Dictionary with kwargs. And That dictionary kwargs for k, v in kwargs.items(): With print (k +'is'+ v +'.') Use.
Dictionary execution result
Taro is a brave man.
Jiro is a warrior.
Saburo is a witch.
Shiro is a monk.
Recommended Posts