Skip to Content
Modifying member variables

We can modify variables that belong to a class the same way that we initialize those member variables. This can be useful when we want to change the value a variable takes on based on something that happens inside of a class method.



Inside the Car class, add a method drive_car that sets self.condition to the string "used".

Remove the call to my_car.display_car() and instead print only the condition of your car.

Then drive your car by calling the drive_car method.

Finally, print the condition of your car again to see how its value changes.

Folder Icon

Take this course for free

Already have an account?