Python“內部類”
阿新 • • 發佈:2018-12-26
# -*- coding:utf-8 -*- class OutClass: static = 3 def __init__(self): self.__a = 1 def printout(self): print self.__a def set_a(self,a): self.__a = a def get_a(self): return self.__a def printout(self): print '外部類輸出其靜態變數',OutClass.static class InnerClass: def __init__(self): self.__b = 2 def printout(self): print self.__b print '從內部類輸出外部類的靜態變數',OutClass.static def set_b(self,b): self.__b = b def get_b(self): return self.__b Outtest = OutClass() Outtest.printout() print Outtest.get_a() InTest = OutClass.InnerClass() InTest.printout() print InTest.get_b() print Outtest print InTest