class A:
def __init__(self):
self.i = 0
def demo(self):
self.a=1
class B(A):
def __init__(self, j = 0):
super().__init__()
self.j = j
print(self.i)
self.demo()
def demo(self):
print(self.a)
def main():
b = B()
print(b.i)
print(b.j)
main()
why am i not able to access self.a inside class b does prefixing a variable with self. will make it an instance variable Thanks
self.a = None. Fist - you will never getAttributeError, second - you will have cleaner code with all your instance variables declared in the same place.