Python: Regarding variable scope. Why don't I need to pass x to Y?
问题 Consider the following code, why don't I need to pass x to Y? class X: def __init__(self): self.a = 1 self.b = 2 self.c = 3 class Y: def A(self): print(x.a,x.b,x.c) x = X() y = Y() y.A() Thank you to the top answers, they really helped me see what was the problem, namely misunderstanding regarding variable scope. I wish I could choose both as correct answer as they are enlightening in their own way. 回答1: From The Python Tutorial: Although scopes are determined statically, they are used