• 多重继承


    通过继承,使得子类具有父类相同的属性,方便子类的调用

    例:

    #生父 
    class Father(object):
        def func(self):
            print('生父打儿子')

    #老王
    class LaoWang():
        def func(self):
            print('老王打儿子')
        def func1(self):
            print('下午等我过来')
           
    #继父
    class StepFather():
        def func(self):
            print('继父打儿子')
        def func1(self):
            print('儿子去买酒,喝完好打你')
           
    #神秘人
    class MysteryMan(Father,LaoWang,StepFather):
        pass

    >>> s=MysteryMan()
    >>> s.func()
    生父打儿子
    >>> s.func1()
    下午等我过来

    class MysteryMan(Father,StepFather,LaoWang):
        pass

    >>> s=MysteryMan()
    >>> s.func()
    生父打儿子
    >>> s.func1()
    儿子去买酒,喝完好打你

    通过例子可以看出,优先继承父类,然后再继承子类(当存在多个子类的时候,优先第一个子类)

  • 相关阅读:
    2020.4.10个人总结
    CG-CTF simple machine
    CG-CTF Our 16bit wars
    CG-CTF Our 16bit Games
    CG-CTF single
    CG-CTF WxyVM2
    Go Channel 详解
    Go语言TCP Socket编程
    golang mysql demo
    YouCompleteMe unavailable: requires Vim compiled with Python 2.x support
  • 原文地址:https://www.cnblogs.com/bang325/p/7189719.html
Copyright © 2020-2023  润新知