Putting It All Together
00:00 Now that you’ve seen argument tuple packing and argument dictionary packing, let’s take a look at how they can be used together for creating a function. If you were going to use positional parameters, argument tuple packing, and argument dictionary packing in a single function definition, you must apply them in that order. Required positional parameters would have to be first, then additional positional arguments, followed by any additional keyword arguments.
So here is an example function definition, which is going to take two required parameters,
b, and then any additional positional arguments are going to be packed into
args, and then following that we can allow for any number of keyword arguments to be passed and packed into the dictionary
And then this function is simply going to display each of the parameter variables, and so we will see the specific values we named for
b, we will see the tuple created for the additional positional parameters, and then we will lastly see the dictionary created with any keyword arguments that were provided.
02:25 And this provides just about as much flexibility as you could ever need in a function interface. Next, we’ll take a look at how you can use multiple unpackings in a function call: the opposite end of using multiple packings in a function definition.
Become a Member to join the conversation.