Summarizing and thinking about the @property of Python

Source: Internet
Author: User

In fact about @property I searched a lot of tutorials to see, because the company used a lot of OOP programming and I have rarely written before, so now to re-fill.

The most obvious difference between the use and the @property is that

 classStudent (object):defGet_score (self):returnSelf._scoredefSet_score (self, value):if  notisinstance (value, int):RaiseValueError ('score must is an integer!')        ifValue < 0orValue > 100:            RaiseValueError ('score must between 0 ~ 100!') Self._score=value#instantiate the Student classx =Student ()#calling the Get_score methodX.get_score () But if you add @property, then X.get_score can run.

This is probably my most obvious and intuitive feeling for @property.

There are many other features that can be used after using @property.

For details, refer to Http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/ 001386820062641f3bcc60a4b164f8d91df476445697b9e000

Liaoche Teacher's tutorial.

Summarizing and thinking about the @property of Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.