Python Use Dict as Name Parameters for Function

January 12, 2019
Unpack list or tuple as function parameters/arguments
def intro(name, age):
  print('My name is {} and I am {} years old'.format(name, age))


intro('desmond', 40)

# use dict
data = {'name': 'Desmond', 'age': 40}
intro(**data)

# use list
data = ['Desmond', 40]
intro(*data)

# use tuple
data = ('Desmond', 40)
intro(*data)
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.