各位前辈大家好 不好意思不知道标题这样描述对不对 主要问题是说 如果我今天在class A里面实体化 class B,有没有办法用class B去修改 class A里的变量或用class A里的function 例如C#的方式是像这样: class A { B son = new B(); son.father=this } class B { A father = null; } 这样如果A里有个变量叫apple 就可以在class B里面用father.apple=??? 来直接修改他的值 请问Python有类似的方法吗? 找了蛮久的不过目前还没看到QQ
你这样做,class B每次都得检查father是不是None或null..才能调用father的方法或属性..为何不直接在B初始方法就传入一个A实体当father?class a __init__(self): self.son = B(self)class B __init__(self,father) self.father=father