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 Instant Objects Method Arguments

By using **kwargs, each instance can now have a different set of attributes for the same class. Is this a valid approach

By using **kwargs, each instance can now have a different set of attributes for the same class. Is this a valid approach? For example, object1 can have (attribute1,2,3) and object2 can have (attribute4,5,6).

1 Answer

Every instance already has different attributes in away. Think of an instance as a copy of the class. If you make an instance of the class, you have made a copy of the class. If you make another instance of the class, you have made another and different copy of the class. Even if both instances have the same attribute values, they are two different objects. Using **kwargs doesn't change the attributes for the class, it changes the attributes for that instance of the class. The thing to remember is that class might have attributes that are the same for every instance of the class and they would be hard coded within the class and wouldn't be supplied when a instance is created. The **kwargs would only be attributes that needed to be supplied or changed for that instance.