class A:
def __init__(self):
print('I am A')
class B(A):
def b(self):
print('I am B.b')
class C(A):
def c(self):
x.b()
if __name__ == '__main__':
x = B()
y = C()
y.c()
How does it work when it comes to 'y.c() '? In C.c(), how can the instance x be called without instantiation before? Thanks a lot, if someone can help.
self.b()? (xis a global variable instantiated in your"__main__"clause).xis a global variable. You created it outside of any function.