Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

浅谈python中的property属性演变过程 | MYAN's Blog #7

Open
MYAN1998 opened this issue Jul 26, 2022 · 0 comments
Open

浅谈python中的property属性演变过程 | MYAN's Blog #7

MYAN1998 opened this issue Jul 26, 2022 · 0 comments

Comments

@MYAN1998
Copy link
Owner

https://myan1998.github.io/posts/930534823/

前言property属性可以用来给属性添加约束,保护数据在有效范围内;使用property属性,将来修改约束条件的时候也很方便,可以在代码的调用方式不变的情况下改变结果。 例子:对于学生类有两个实例变量,一个是姓名,一个是年龄;对学生的年龄加以约束,将学生的年龄控制在6-18岁之间,倘若创建的学生对象的年龄不在6-18岁之间,则不接收该学生; 实现上述要求的方法有如下这么几种。 实现方法方法112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant