2020年1月15日 MRKJ 继承 page197

class CLASSNAME(base)

  ‘’‘类的帮助信息’‘’

  statement

 

复制代码
class Fruit:
    color='green'
    def harvest(self,color):
        print('I am %s'%color)
        print(Fruit.color)

class Apple(Fruit):
    color = 'red'
    def __init__(self):
        print('apple')

class Orange(Fruit):
    color='yellow'
    def __init__(self):
        print('orange')

a=Apple()
o=Orange()
print(a.harvest(Apple.color))
print(o.harvest(Orange.color))
复制代码

》》》》

apple
orange
I am red
green
None
I am yellow
green
None

posted @   小圣庄  阅读(114)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示