0
class Engine():
    def start(self):
        print("Started")
        pass
    def stop(self):
        pass

class Car():
    engine_cls = Engine
    def __init__(self):
        self.engine = self.engine_cls()
    def start(self):
        print("Car started")

car = Car()
car.start()

Can someone explain me why cant we use:

class Car():
    engine_cls = Engine()

Tried: class Car(): engine_cls = Engine()

And encountered object not callable. Want to understand the difference in using the parenthesis.

    self.engine = self.engine_cls()
TypeError: 'Engine' object is not callable
suri
  • 1
  • `Engine` is a class and `Engine()` is an instance (object) of that class. In the latter case `self.engine_cls()` is equivalent to `Engine()()` which doesn't make sense. – Selcuk Nov 24 '22 at 00:53

0 Answers0