v Unpacking Function Arguments - Python

Unpacking Function Arguments

Interesting in learning more? Check out Fluent Python

Create Argument Objects

# Create a dictionary of arguments
argument_dict = {'a':'Alpha', 'b':'Bravo'}

# Create a list of arguments
argument_list = ['Alpha', 'Bravo']

Create A Simple Function

# Create a function that takes two inputs
def simple_function(a, b):
    # and prints them combined
    return a + b

Run the Function With Unpacked Arguments

# Run the function with the unpacked argument dictionary
simple_function(**argument_dict)
'AlphaBravo'
# Run the function with the unpacked argument list
simple_function(*argument_list)
'AlphaBravo'