class Geese:
'''大雁类'''
def __init__(self,beak,wing,claw):
print('我是大雁类!我有以下特征:')
print(beak)
print(wing)
print(claw)
def fly(self,state):
print(state)
beak_1='喙的基部较高,长度和头部的长度几乎相等'
wing_1='翅膀长而尖'
claw_1='爪子是蹼状的'
wildGoose=Geese(beak_1,wing_1,claw_1)
wildGoose.fly('我飞行的时候,一会儿排成个人字,一会儿排成个一字')
class Geese:
'''雁类'''
neck='脖子较长'
wing='振翅频率高'
leg='腿位于身体的中心支点'
number=0
def __init__(self):
Geese.number+=1
print('\n我是第'+str(Geese.number)+'只大雁,我属于雁类!我有以下特征:')
print(Geese.neck)
print(Geese.wing)
print(Geese.leg)
list1=[]
for i in range(4):
list1.append(Geese())
print('一共有'+str(Geese.number)+'只大雁')
class Fruit:
color='绿色'
def harvest(self,color):
print('水果是:'+color+'的!')
print('水果已经收获...')
print('水果原来是:'+Fruit.color+'的!')
class Apple(Fruit):
color='红色'
def __init__(self):
print('我是苹果')
class Orange(Fruit):
color='绿色'
def __init__(self):
print('我是橘子')
apple=Apple()
apple.harvest(apple.color)
orange=Orange()
orange.harvest(orange.color)
class Fruit:
def __init__(self,color='绿色'):
Fruit.color=color
def harvest(self,color):
print('水果是:'+self.color+'的!')
print('水果已经收获....')
print('水果原来是:'+Fruit.color+'的!')
class Apple(Fruit):
color='红色'
def __init__(self):
print("我是苹果")
super().__init__()
class Sapodilla(Fruit):
def __init__(self,color):
print("\n我是人参果")
super().__init__(color)
def harvest(self,color):
print('人参果是:'+color+'的!')
print('人参果已经收获....')
print('人参果原来是:'+Fruit.color+'的!')
apple=Apple()
apple.harvest(apple.color)
sapodilla=Sapodilla('白色')
sapodilla.harvest('金黄色带紫色条纹')
标签:__,对象,self,color,Fruit,print,程序设计,面对,def
From: https://www.cnblogs.com/whc123/p/16986371.html