python内部类

  1. 内部类实例:
    # _*_ 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()

     

  2. 输出结果:
    D:\软件安装\Python3.7.4\python.exe E:/python/pythonfile20190907/OOP4.py
    这是外部类parent
    这是内部类son
    
    Process finished with exit code 0

     

posted on 2019-09-09 14:06  ybl20000418  阅读(131)  评论(0编辑  收藏  举报

导航