Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.