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 What Are Objects And Classes?

What does he mean by the "instance is responsible"?

When that instance is used, like when we change an attribute on it or call a method, the instance is responsible and not the class it was instantiated from"

James Joseph
James Joseph
4,885 Points

When you give a variable an object of the class you've used you are creating a duplicate copy of that class for usage essentially creating an instance of it.

What he's saying is when you change an attribute that instance of the object is affected by the change, not the class you originally coded.

Example:

car = ProjectCar()

car.max_speed  = 120

That max_speed has changed only on the instance of car it has not changed on the class ProjectCar(). If I wanted to change original max speed I would have to edit the class of ProjectCar()

class ProjectCar:
    def __init__(self):
        self.max_speed = 120
        self.colour = "red"

Hope that helps

1 Answer

I had the same question. That helps. Thank you James.