<span style="font-size:18px;">class fruit(object):price = 0 #类属性def __init__(self):self.color = 'red' #实例属性size = 10 if __name__ == '__main__':apple = fruit()print 'apple',apple.priceprint apple.colorapple.price = 20print 'apple',apple.priceapple.color = 'yellow'fruit.price = 25fruit.color = 'blue'print apple.color banana = fruit() print '===================' print banana.price print banana.colorred apple 20 yellow =================== 25 red </span>
class Apple(fruit):pass
print Apple.__bases__
print Apple.__dict__
print Apple.__module__
print Apple.__doc__
class fruit1():price = 0;def __init__(self):self.__color = 'blue'def getcolor(self):print self.__color@staticmethoddef getprice():print fruit1.pricedef __getprice():fruit1.price = fruit1.price+10print fruit1.price#print fruit.__colorcount = staticmethod(__getprice)
if __name__ == '__main__':apple = fruit1()apple.getcolor()fruit1.count()banana = fruit1()fruit1.count()fruit1.getprice()
输出:
blue
10
20
20
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态