#-*-coding:utf-8-*- __author__ = 'allen' class Hello: def __init__(self,name): self._name = name def sayHello(self): #定义一个方法 print("Hello {0}".format(self._name)) class Hi(Hello): def __init__(self,name): Hello.__init__(self,name) #self._name = name def sayHi(self): print("Hi {0}".format(self._name)) h = Hello("Python") h.sayHello() h1 = Hi("Allen") h1.sayHi()
Q:
1. h.sayhello 可以调用h = Hi("Allen")
2. Hello.__init__(slef,name) 换成 self.name = name