python(父类与子类的继承)

创建类 '''
class Person():##定义名字类
def init(self,name):
self.name = name
class MDPerson(Person):##创建医生类
def init(self,name):
self.name="Doctor"+name
class JDPerson(Person):##创建律师类
def init(self,name):
self.name=name+",Esquire"
'''
用类创建对象 【python(父类与子类的继承)】'''
person = Person('Fudd')##用类创建对象
doctor = MDPerson('Fudd')
lawyer = JDPerson('Fudd')
'''
输出结果 '''
print(person.name)
print(doctor.name)
print(lawyer.name)
'''
结果 1-------Fudd
2------DoctorFudd
3------Fudd,Esquire

    推荐阅读