Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Dictionaries Packing and Unpacking Dictionaries

Irakli Tchigladze
Irakli Tchigladze
1,390 Points

Overruling the "None" arguments while Packing/unpacking

While showing how packing works, Kenneth adds "Name" = None in the packer() function arguments, before the **kwargs, and because of that addition, there isn't that pair of key and value in the dictionary anymore. But when unpacking, he sets both arguments, first_name and last_name to none, yet, when he calls the function and includes the unpacker, they appear to be working, which seems backwards. Why? Is it just how it works? Am i missing something?

1 Answer

Unpacking dictionary as argument of function is equivalent to calling function with keyword arguments (key=value pairs).

When you call unpacker function with dictionary with values for last_name and first_name, you override default values for these parameters. Set first_name and last_name to None in function definition only means that you provide default values for these parameters.