首页 > 编程语言 > 详细

Python内置函数之classmetho staticmethod

时间:2019-02-17 12:22:57      阅读:229      评论:0      收藏:0      [点我收藏+]

当对类的静态属性进行修改时(不需要借助于对象就行类静态属性的修改)

 

 

class Goods:
    discount = 0.5
    def __init__(self,name,price):
        self.name = name
        self.__price = price

    @property
    def price(self):
        return  self.__price * Goods.discount
    @classmethod 
    def changeDiscount(cls,new_discount):
        cls.discount = new_discount

apple = Goods(apple,10)
Goods.changeDiscount(0.1)
print(apple.price)

 

Python内置函数之classmetho staticmethod

原文:https://www.cnblogs.com/wc89/p/10390447.html

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