Why does it print 0 and not 24? Also, why does it bring up an error if I dont explicitly define num in the System class even though im doing it in the constructor?
from abc import ABC, abstractmethod
class System(ABC):
num = 0
def __init__(self, input):
self.num = input
return
@abstractmethod
def getNum(self):
pass
class FirstSystem(System):
def __init__(self, input):
super().__init__(input)
return
def getNum(self):
return super().num
foo = FirstSystem(24)
print(foo.getNum())
num) in the first place.inputis a bad variable name since it shadows the builtininputfunction. You can see in the syntax highlighting thatinputis highlighted as a builtin (orange). I'd recommend using the attribute name instead,num.System.__init__.