fork download
  1. class A:
  2. def __init__(self, x, y):
  3. self.n = x
  4. self.inner = B(self, y)
  5.  
  6. def f(self):
  7. return self.n ** 2
  8.  
  9. class B:
  10. def __init__(self, outer, y):
  11. self.outer = outer
  12. self.n = y
  13.  
  14. def f(self):
  15. return self.outer.f()
  16.  
  17. a = A(2, 3)
  18. print((a.f(), a.inner.f()))
Success #stdin #stdout 0.03s 9632KB
stdin
Standard input is empty
stdout
(4, 4)