创建类.py class Cmm: def __init__(self, a): self.x = a self.m1 = 5 self.m2 = 6 print("这是外部函数") self.jiafa() def jiafa(self): f = self.m1 + self.m2 print(f) def kkk( m): nonlocal f f1 = f * m + self.m1 def h1(): nonlocal f1 q1 = f1 * 2 return q1 return h1() def kkk2(): nonlocal f f2 = f * 3 print(f2) self.kkk = kkk self.kkk2 = kkk2
调用类.py
from 创建类 import Cmm m = Cmm(3) l1 = m.jiafa() print(m.kkk(5)) m.kkk2()
运行结果:
这是外部函数
11
11
120
33
Process finished with exit code 0