python setter
时间: 2023-08-27 17:20:15 浏览: 87
Python如何使用@property @x.setter及@x.deleter
在Python中,setter是一种用于给属性赋值的方法。setter是通过使用@property装饰器和对应的.setter装饰器来定义的。首先,需要在属性上方添加@property装饰器,这将定义一个getter方法,用于获取属性的值。然后,在getter方法下方添加一个带有与属性相同名称的.setter装饰器的方法,该方法用于设置属性的值。setter方法需要一个参数,用来接收
#### 引用[.reference_title]
- *1* *3* [Python中的getter、setter、deleter](https://blog.csdn.net/JENREY/article/details/128595505)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* [Python中的property, setter装饰器](https://blog.csdn.net/david830_wu/article/details/66586977)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文