• 技术文章 >Python技术 >Python基础教程

    python继承的多种类型

    小妮浅浅小妮浅浅2021-09-01 09:32:04原创3069

    类型说明

    单一继承

    1、单级继承使派生类能够从单个父类继承特征。

    多级继承

    2、多级继承使派生类能够从直接父类继承属性。

    而直接父类又从其父类继承属性。

    3、层次继承

    分层级继承使多个派生类能够从父类继承属性。

    4、多重继承

    多级继承使一个派生类可以从多个基类继承属性。

    实例

    class employee1()://Parent class
        def __init__(self, name, age, salary): 
            self.name = name
            self.age = age
            self.salary = salary
     
    class employee2()://Parent class
        def __init__(self,name,age,salary,id):
         self.name = name
         self.age = age
         self.salary = salary
         self.id = id
     
    class childemployee(employee1,employee2):
        def __init__(self, name, age, salary,id):
         self.name = name
         self.age = age
         self.salary = salary
         self.id = id
    emp1 = employee1('harshit',22,1000)
    emp2 = employee2('arjun',23,2000,1234)
     
    print(emp1.age)
    print(emp2.id)

    以上就是python继承的多种类型,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python继承
    品易云
    上一篇:python循环语句的两种类型 下一篇:python中pandas模块查看DataFrame

    相关文章推荐

    • python继承是如何实现的• python继承类中如何重写?• python继承是什么?• python继承的特征有哪些?• python继承的基类属性分析• Python继承的原理分析

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网