Title: Unpacking Function Arguments
Slug: unpacking_function_arguments
Summary: Unpacking Function Arguments in Python.
Date: 2016-01-23 12:00
Category: Python
Tags: Basics
Authors: Chris Albon
Interesting in learning more? Check out Fluent Python
In [1]:
# Create a dictionary of arguments
argument_dict = {'a':'Alpha', 'b':'Bravo'}
# Create a list of arguments
argument_list = ['Alpha', 'Bravo']
In [2]:
# Create a function that takes two inputs
def simple_function(a, b):
# and prints them combined
return a + b
In [3]:
# Run the function with the unpacked argument dictionary
simple_function(**argument_dict)
Out[3]:
In [4]:
# Run the function with the unpacked argument list
simple_function(*argument_list)
Out[4]: