继承

#-*-coding:utf-8-*-
__author__ = "logan.xu"


class People:
def __init__(self,name,age):
self.name = name
self.age = age

def eat(self):
print("%s is eating....." %self.name)

def talk(self):
print("%s is talking..." %self.name)

def sleep(self):
print("%s is sleeping..." %self.name)

class Man(People): #子类继承父类people

def piao(self):
print("%s is piaoing....20s...done"%self.name)
#重构父类的方法
def sleep(self):
People.sleep(self) #调用父类的方法把self传进去
print("man is sleeping")

#添加子类woman
class Woman(People):
def get_birth(self):
print("%s is born a baby..."%self.name)

def cook(self):
print("%s cooking many food,i love it ..."%self.name)

def shopping(self):
print("%s My wife so pretty,dress on beautiful clothes."
"it's just white fu mei's long legs"%self.name)

#两个子类之间不能相互调用类的方法
#m1实例化
m1 = Man("Jordan",22)
m1.eat()
m1.piao()
m1.sleep()

#w1实例化
w1 = Woman("Lydia",20)
w1.get_birth()
w1.cook()
w1.shopping()





原文地址:https://www.cnblogs.com/drizzle-xu/p/8931631.html