-3

I made a function drive_car inside of the class car, but I do not know how to call it from the class it is defined in, outside of the class, while staying inside of its class.

class car:
      def drive_car():
          print("car go vroom vroom")
car.drive_car() # -- gives error message
  • 3
    This is covered in any tutorial on classes. Stack Overflow is not intended to replace existing tutorials and documentation. You seem to have skipped the part about instantiating a class, as well as how to invoke instance methods (functions for class objects). – Prune May 02 '21 at 23:32

1 Answers1

0

There are 2 total ways you can call drive_car()

  • Convert drive_car() into a static method. This way you can call this via car.drive_car()
  • Or, you instantiate the class car and then call drive_car() like so: car().drive_car()
12944qwerty
  • 2,001
  • 1
  • 10
  • 30