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 String Formatting with Dictionaries

I got the correct answer but I don't think I understand this very well.

Once we hit the double "*" topic I got very confused as to what its actually doing and why it worked in the .format. My best guess would be it worked because the dict they used to test our code holds both keys that are hard-coded into the {}, So there is no needing to worry about the names not matching.

1 Answer

Steven Parker
Steven Parker
230,995 Points

It sounds like your understanding is correct. Since the dictionary keys are the same as placeholder names, simply unpacking the dictionary provides everything needed by "format" to fill in the values.

now if there were more in the dictionary then needed to fill the placeholders would python prevent an error from occurring by only utilizing what is needed? Or would we need to add our own preventative try and except block?