Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Instant Objects What Are Objects And Classes?

Ryan Hartigan
Ryan Hartigan
3,424 Points

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,761 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.


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.