首页 > 编程语言 > 详细

python继承

时间:2018-07-01 18:45:38      阅读:209      评论:0      收藏:0      [点我收藏+]

继承的时候,调用父类的构造函数的方法:使用super()函数,只需要调用一次就行,会自动调用所有父类和父类的父类的构造函数

# -*- coding: utf-8 -*-
class A(object):
    def __init__(self):
        super(A, self).__init__()
        print("A__init__")

class B(object):
    def __init__(self):
        super(B, self).__init__()
        print("B__init__")

class C(A, B):
    def __init__(self):
        super(C, self).__init__() # 等价 super().__init__()
        print("C__init__")

x = C()

  

 输出为:

 技术分享图片

 

python继承

原文:https://www.cnblogs.com/ACGame/p/9093734.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!