首页 > 编程语言 >python property使用

python property使用

时间:2023-01-18 14:32:46浏览次数:39  
标签:__ Goods python price 使用 ._ property self def

class Goods():
def __init__(self):
self._price = ""

@property
def price(self):
return self._price

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

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

g = Goods()
a = g.price
print(a)

g.price = 123
b = g.price
print(b)

del g.price

标签:__,Goods,python,price,使用,._,property,self,def
From: https://blog.51cto.com/haoyonghui/6019237

相关文章

  • python 引用父类super
    classParent():def__init__(self,name):print(name)classSon(Parent):def__init__(self,name):super().__init__(name)s=Son(name="ccc")......
  • 类型提示和python函数中'->'的用法
    一、类型提示在python中,我们定义一个有参函数,调用该函数时需要传入参数,如下所示:#定义一个简单的函数defget_full_name(first_name,last_name):full_name=fir......
  • C#使用枚举类型作为数据源
    C#使用Enum.GetValues<TEnum>()方法获取枚举数组集合TEnum[],基于此可使用枚举的所有类型作为下拉框等控件的数据源使用。1、枚举定义internalenumIconResolution{......
  • 使用dayjs关于日期格式化的一些记录
    本篇文章主要是看了下面这篇博文和知乎上的讨论出现的http://www.cielni.com/2020/01/10/java-date-format/#morehttps://zhuanlan.zhihu.com/p/100648038通常前端会使......
  • SpringShell使用说明
    一、添加依耐(pom.xml)<dependency><groupId>org.springframework.shell</groupId><artifactId>spring-shell-starter</artifactId><version>2.1.4</version><......
  • 如果有效python code review
    这篇文章主要介绍一些工具,方法,可以帮助我们做codepre-commit检查,这样我们做codereview之前,这些工具方法就帮我们解决了一些代码风格的问题和静态检查就能检查出来......
  • Python导入Excel表格数据并以字典dict格式保存
      本文介绍基于Python语言,将一个Excel表格文件中的数据导入到Python中,并将其通过字典格式来存储的方法。  我们以如下所示的一个表格(.xlsx格式)作为简单的示例。其中,表......
  • 使用MyBatis-Plus报错:Invalid bound statement (not found):无法使用selectById云云
    详见MP的gitee源码Issue:https://gitee.com/baomidou/mybatis-plus/issues/I6AZIOMP版本3.5.2最近遇到了Invalidboundstatement(notfound)这个报错,网上都是说xml和mapp......
  • python3中(?P的正则应用
    importre'''其中?P可以理解为将字符串s分组处理并命名为province、city、block'''s='13g00x21yy'res=re.search('(?P<province>\d{2}).*(?P<city>\d{2}).*(?P<block>\d......
  • 使用Python的一维卷积
    学习&转载文章:使用Python的一维卷积背景在开发机器学习算法时,最重要的事情之一(如果不是最重要的话)是提取最相关的特征,这是在项目的特征工程部分中完成的。在CNNs中,此......