模仿静态变量 (static) 另一案例。
演示一个 python 作用域使用方法
class Num: nNum = 1 def inc(self): self.nNum += 1 print(f'nNum = {self.nNum}') if __name__ == '__main__': nNum = 2 inst = Num() for i in range(3): nNum += 1 print(f'The num = {nNum}') inst.inc()