- 内部类实例:
# _*_ utf-8 _*_: # author:Administrator class myouter: def __init__(self,name): self.name=name def output(self): print("这是外部类{name}".format(name=self.name)) class myinner: def __init__(self,inname): self.inname=inname def output(self): print("这是内部类{name}".format(name=self.inname)) if __name__=="__main__": p=myouter('parent') p.output() q=myouter.myinner('son') q.output()
- 输出结果:
D:软件安装Python3.7.4python.exe E:/python/pythonfile20190907/OOP4.py 这是外部类parent 这是内部类son Process finished with exit code 0