Python基础-类的继承

#父类方法的重写
class AxFather(object):
    def makeMoney(self):
        print('今天挣了1000w')

class Ax(AxFather):
    def makeMoney(self):  #重写了父类的方法
        print('今天挣了2000w')
ax=Ax()
ax.makeMoney()

2,父类方法的修改

class AxFather(object):
    def __init__(self,op):
        print('父类',op)

    def makeMoney(self):
        print('今天挣了1000w')

class Ax(AxFather):

    def __init__(self,op,code):
        # AxFather.__init__(self,op)#先调用一下父类的构造方法,有父类的功能
        #如果想修改父类的构造方法,那么你就先调用父类的方法
        super(Ax,self).__init__(op)#通上面的功能是一样的,写的方式不一样而已
        #super中传入本类,不是父类,super自动帮助本类找到父类
        print('这是Ax',op,code)

    def makeMoney(self):
        print('今天挣了2000w')

Ax('抽烟,喝酒','python')#实例化后,没保存
原文地址:https://www.cnblogs.com/niuniu2018/p/8007244.html