Skip to main content
Ask a Question
Harshith V
Wandertech
Asked a question 9 months ago

class T: def show(self): self.n1 =7 print("Base class method called") class S(T): def show(self): self.n2 =70 print('Derived class is',self.n1+self.n2) a = S() print(a.show()) Why am I not able to call self .n1? --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-25-9c5cdf1e1866> in <module> 8 print('Derived class is',self.n1+self.n2) 9 a = S() ---> 10 print(a.show()) <ipython-input-25-9c5cdf1e1866> in show(self) 6 def show(self): 7 self.n2 =70 ----> 8 print('Derived class is',self.n1+self.n2) 9 a = S() 10 print(a.show()) AttributeError: 'S' object has no attribute 'n1'

Fuel your ambition, discover your passion and achieve your professional goals with LetsUpgrade.
Sign Up Now