Skip to content

Commit 380f449

Browse files
authored
update 装饰器
1 parent 41769b7 commit 380f449

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Day01-15/Day09/面向对象进阶.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### @property装饰器
66

7+
https://www.jianshu.com/p/29e436ff48c8
8+
79
之前我们讨论过Python中属性和方法访问权限的问题,虽然我们不建议将属性设置为私有的,但是如果直接将属性暴露给外界也是有问题的,比如我们没有办法检查赋给属性的值是否有效。我们之前的建议是将属性命名以单下划线开头,通过这种方式来暗示属性是受保护的,不建议外界直接访问,那么如果想访问属性可以通过属性的getter(访问器)和setter(修改器)方法进行对应的操作。如果要做到这点,就可以考虑使用@property包装器来包装getter和setter方法,使得对属性的访问既安全又方便,代码如下所示。
810

911
```Python

0 commit comments

Comments
 (0)