'''
class Geese:
def __init__(self):
print("fuck")
wildgooes=Geese()
class Goose:
neck="long"
leg="xi"
wing="wu"
def __init__(self,wing,mouth): #带参构造方法
print("fuck")
print(wing+"big")
print(mouth+"red")
def fly(self,w):
print(w)
def fun1(self):
print(Goose.neck)
go=Goose("11","22")
go.fly(1)
go.fun1()
print(go.neck)
class Swan:
_neck_swan="swan's neck is long" #protected,允许类和子类访问
__neck_swan="long" #private,允许类本身访问n
def __init__(self):
print(Swan._neck_swan)
print(Swan.__neck_swan)
swan=Swan()
print(swan._neck_swan)
class Rect:
def __init__(self,width,height):
self.width=width
self.height=height
@property #将方法转化为属性
def area(self):
return self.width*self.height
rect=Rect(10,10)
print(rect.area)
class TVshow:
list_film=["zhanglang2","bbbs","ybb"]
def __init__(self,show):
self.__show=show
@property
def show(self):
return self.__show
@show.setter #修改方法属性
def show(self,value):
if value in TVshow.list_film:
self.__show="you chose <<"+value+">>"
else:
self.__show="don't exsit"
tvshow=TVshow("www")
print(tvshow.show)
tvshow.show="ybb"
print(tvshow.show)
tvshow.show="233"
print(tvshow.show)
'''
class fruit:
color="green"
def __init__(self,color):
print(color)
def harvest(self,color):
print("the color is"+color)
print("fruit has been harvested")
print("the original color is"+fruit.color)
class apple(fruit):
color="red"
def __init__(self):
print("this is applr")
class orange(fruit): #继承,可以继承方法,属性
def __init__(self):
print("this is orange")
Apple=apple()
Apple.harvest(Apple.color)
Orange=orange()
Orange.harvest(Orange.color)
class peach(fruit):
color ="pink"
def __init__(self):
super().__init__(super().color) #用super()调用基类的__init__和属性
print("this is peach")
def harvest(self):
print("the color of peach is "+peach.color)
Peach=peach()
Peach.harvest()