2020年1月15日 MRKJ 继承 page197

荒凉一梦 提交于 2020-01-15 23:39:32

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!