属性设置

!/usr/bin/env python

-- coding: utf-8 --

@Time : 2017/5/27 7:15

@Author : joj

@Site :

@File : Goods.py

@Software: PyCharm

class Goods(object):
def init(self):
self.original_price = 100
self.discount = 0.8

@property
def price(self):
    new_price = self.original_price * self.discount
    return new_price

@price.setter
def price(self, value):
    self.original_price = value

@price.deleter
def price(self):
    del self.original_price

obj = Goods()

print obj.price
obj.price = 200
print obj.price
del obj.price

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 这是一篇相当于,我开发过程中的一篇笔记吧。可能比较杂乱,是我的第一篇文章。 1.应用三方地图软件的时候:地图功能显...
    凌峰Mical阅读 1,573评论 7 26
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,845评论 18 139
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,797评论 0 23
  • 1、马小军 马小军是六年级一班的班长,成绩优秀。 同学们每天下午最后一节课前都会把课堂笔记本交到他这里,放学后,他...
    幕后B阅读 251评论 0 0
  • Menu bar is hiddenThis may solve the problem : Active wor...
    JaedenKil阅读 149评论 0 0