首页 > 其他 > 详细

2020年1月15日 MRKJ 继承 page197

时间:2020-01-15 23:21:20      阅读:95      评论:0      收藏:0      [点我收藏+]

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

2020年1月15日 MRKJ 继承 page197

原文:https://www.cnblogs.com/python1988/p/12199156.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!