给出如下代码:
class a():
x=1
class b()
x=3
print x
如何在类a中使用类b中的x值?
我是这样的例子:
class A:
def add():
x=1
class B:
def addmore():
y=1
如何在A类中获得Y的值
答案 0 :(得分:1)
If i understood you right then this is your code, and this is your access to the x variable:
class A():
x=1
class B():
x=3
aInstance = A()
print aInstance.x
'1'
print aInstance.B.x
'3'