摘要:
# method 英文是方法的意思 # classmethod 类方法 # 当一个类中的方法中只涉及操作类的静态属性时,此时在逻辑上,我们想要直接通过类名就可以调用这个方法去修改类的静态属性,此时可以用这个内置装饰器函数 # staticmethod 静态方法 # 类的方法 classmethod class Goods: discount = 0.5 # 折扣 ... 阅读全文
posted @ 2018-10-03 11:44
_小溢
阅读(332)
评论(0)
推荐(0)
摘要:
# property # 内置装饰器函数 只在面向对象中使用 # 装饰后效果:将类的方法伪装成属性 # 被property装饰后的方法,不能带除了self外的任何参数 from math import pi class Circle: def __init__(self, r): self.r = r def perimeter(sel... 阅读全文
posted @ 2018-10-03 11:12
_小溢
阅读(1710)
评论(0)
推荐(1)

浙公网安备 33010602011771号