Reply To: Classes and Objects in Python

Welcome to Python Land Forums The Python Tutorial Classes and Objects in Python Reply To: Classes and Objects in Python


Yes I think that’s exactly what’s happening. I see the page got updated to explicitly tell you to hit enter twice after pasting the class. Only after that, you can create a car object.

So first copy-paste this:

class Car:
    speed = 0
    started = False
    def start(self):
        self.started = True
        print("Car started, let's ride!")
    def increase_speed(self, delta):
        if self.started:
            self.speed = self.speed + delta
            print("You need to start the car first")
    def stop(self):
        self.speed = 0
car = Car()

And hit enter twice. Then you can use the class, e.g. with car = Car()