class Base(object):
    def __init__(self,name,age,iphone):
        self.name = name
        self.age = age
        self.iphone = iphone

    def do(self):
        print("hello {name}".format(name = self.name))

        return self.name + self.age + self.iphone

    def send1(self):
        raise NotImplementedError("子类中必须重写send方法")
    # 用这个方法约束子类必须要写某个方法,如果不写则会报错


class Foo(Base):
    def send1(self):
        print("ok")

obj = Foo("cui","232","123")

obj.send1()

 

 主要是这里,send1这个方法必须在子类中重写

 

 

使用的场景

父类中定义了一个方法,如果子类要想使用这个方法,则必须要自己的类中定义,不能使用父类的的方法

 

posted on 2019-04-09 23:08  bainianminguo  阅读(480)  评论(0)    收藏  举报