zoukankan      html  css  js  c++  java
  • 子类重用父类的功能super

    # class OldboyPeople:
    # school = 'oldboy'
    # def __init__(self,name,age,gender):
    # self.name=name
    # self.age=age
    # self.gender=gender
    # def tell_info(self):
    # print('<名字:<%s> 年龄:<%s> 性别:<%s>' %(self.name,self.age,self.gender))
    #
    # class OldStudent(OldboyPeople):
    # def __init__(self,name,age,gender,course):
    # # OldboyPeople.__init__(self,name,age,gender)
    # super().__init__(name,age,gender)
    # self.course=course
    # def learn(self):
    # print('%s is learning'%self.name)
    # def tell_info(self):
    # print('我是学生:',end='')
    # OldboyPeople.tell_info(self)
    #
    # stu1=OldStudent('婉婷',18,'female','python')
    # stu1.tell_info()
    '''
    我是学生:<名字:<婉婷> 年龄:<18> 性别:<female>
    '''
    # print(stu1.name,stu1.age,stu1.gender,stu1.course)
    '''
    婉婷 18 female python
    '''
    # class OldboyPeople:
    # school = 'oldboy'
    # def __init__(self,name,age,gender):
    # self.name=name
    # self.age=age
    # self.gender=gender
    # def tell_info(self):
    # print('<名字:<%s> 年龄:<%s> 性别:<%s>' %(self.name,self.age,self.gender))
    #
    # class OldStudent(OldboyPeople):
    # def __init__(self,name,age,gender,course):
    # super().__init__(name,age,gender)
    # self.course=course
    # def learn(self):
    # print('%s is learning'%self.name)
    # def tell_info(self):
    # print('我是学生:',end='')
    # super().tell_info()
    # stu1=OldStudent('婉婷',18,'female','python')
    # stu1.tell_info()
    '''
    我是学生:<名字:<婉婷> 年龄:<18> 性别:<female>
    '''
    # class Foo:
    # def f1(self):
    # print('Foo.f1')
    # super().f2()
    # class Bar:
    # def f2(self):
    # print('Bar.f2')
    # class Sub(Foo,Bar):
    # pass
    # s=Sub()
    # print(Sub.mro())
    '''
    [<class '__main__.Sub'>,
    <class '__main__.Foo'>,
    <class '__main__.Bar'>,
    <class 'object'>]
    '''
    # s.f1()
    '''
    Foo.f1
    Bar.f2
    '''
    # class Foo:
    # def f2(self):
    # print('==>')
    # def f1(self):
    # print('Foo.f1')
    # super().f2() # 只要写super就是从当前类的下一个开始调
    # class Bar:
    # def f2(self):
    # print('Bar.f2')
    # class Sub(Foo,Bar):
    # pass
    # s=Sub()
    # s.f1()
    '''
    Foo.f1
    Bar.f2
    '''
    # class Foo:
    # def f2(self):
    # print('==>')
    # def f1(self):
    # print('Foo.f1')
    # Foo.f2(123)
    # class Bar:
    # def f2(self):
    # print('Bar.f2')
    # class Sub(Foo,Bar):
    # pass
    # s=Sub()
    # s.f1()
    '''
    Foo.f1
    ==>
    '''
  • 相关阅读:
    分布式版本控制系统Git-----5.Git 的push命令总结
    分布式版本控制系统Git-----4.Git 常用命令整理
    分布式版本控制系统Git-----3.图形化Tortoisegit创建本地库并且提交到远程服务器上
    分布式版本控制系统Git-----2.上传至远程仓库之基础版
    分布式版本控制系统Git-----1.Git 初识
    JavaWeb笔记03-Servlet
    JavaWeb笔记01-XML
    Emmet的html语法
    npm常用命令
    Node.js中事件的循环
  • 原文地址:https://www.cnblogs.com/0B0S/p/12088348.html
Copyright © 2011-2022 走看看