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 Master Class

need help on master class (challenge task 1 of 3)

I am getting an error: "Bummer! Try again!"

class RaceCar:
    __init__ = "color", "fuel_remaining"

def setattr(self.RaceCar):

1 Answer

Rich Zimmerman
Rich Zimmerman
24,063 Points
class RaceCar:
    def __init__(self, color, fuel_remaining, **kwargs):
        self.color = color
        self.fuel_remaining = fuel_remaining

        for key, value in kwargs.items():
            setattr(self, key, value)

the init function sets the variables of the class when instantiated, keep in mind that creating a class like this is just defining the class's methods and properties. It's not actually being USED yet.

so when instantiating a RaceCar class, you would do something like this

my_car = RaceCar('black', 50)

# prints "black"

# would print 50

and kwargs are optional for any other key : value pairs passed as parameters when you create a new instance of the class.