#定义一个基类Bird 类属性have_feather ,way_of_reproduction,初始化方法__init__() ,方法move()
#定义两个子类 Chicken 和 Oriole 添加属性way_of_move and possible_in_KFC
class Bird(object):
have_feather = True
way_of_reproduction='egg'
def __init__(self,more_words):
print('We are happy birds.',more_words)
def move(self,dx,dy):
position = [0,0]
position[0] = position[0]+dx
position[1] = position[1]+dy
return position
class Chicken(Bird):
way_of_move = 'walk'
possible_in_KFC = True
class Oriole(Bird):
way_of_move = 'fly'
possible_in_KFC = False
summer = Bird("I am a happy bird")
print(summer.way_of_reproduction)
print('after move',summer.move(5,8))
summer = Chicken("I am a happy chicken")
print(summer.have_feather)
print('after move',summer.move(4,7))
print(summer.way_of_move)
summer = Oriole("I am a happy Oriole")
print(summer.have_feather)
print('after move',summer.move(3,10))
print(summer.way_of_move)
#定义一个类Human 类属性laugh ,list:test
#初始化函数,方法printGender,show_laugh,laugh_10th
class Human(object):
laugh = 1
test = ['haha','hehe']
def __init__(self,input_gender):
self.gender = input_gender
def printGender(self):
print(self.gender)
def show_laugh(self):
print(self.laugh)
def laugh_10th(self):
for i in range(10):
self.show_laugh()
lilei = Human('male')
lilei.show_laugh()
Human.laugh += 1
viease = Human('zhangsan')
viease.show_laugh()
Human.test[0] = 'enen'
print(lilei.test)
lilei.test[0] = 'heihei'
print(viease.test)