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 Object-Oriented Python (retired) Inheritance Instance Methods

Why do we unpack a dictionary, if there isn't a dictionary specified (Self, **kwargs) ?

Why do we unpack a dictionary, if there isn't a dictionary specified (Self, **kwargs) ?

def init (self, **kwargs): # during initialization the first parameter is within this instance, unpack dictionary ??

why are we unpacking the dictionary as a parameter to the function.

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

We're actually packing the dictionary here. The ** allows us to take any number of keyword arguments and turns them into a dict when we get into the method itself.

Kevin Faust
Kevin Faust
15,353 Points

This is a sidecomment but you never pass in a dictionary when creating an object and this leads to the mass confusion. Why are we packing a dictionary, why are we using setattr, etc. when we are not doing it and not once have you shown it either. It would have been better if an example was shown