What do you do with the property in Python?

Source: Internet
Author: User

First, a section of official document pressure yajing.
Property (fget=none, fset=none, fdel=none, doc=none)

Return a property attribute.

Fget is a function for getting an attribute value, likewise fset are a function for setting, and fdel a function for del ' ing, an attribute. Typical use are to define a managed attribute x:

ClassC:Def__init__(Self):Self._x=NoneDefGetx(Self):ReturnSelf._x def setx (self value): self. _x = value def delx ( selfdel self. _x x = property (getxsetxdelx "I ' m the ' x ' property." )               /span>                

If then C was an instance of C, c.x would invoke the getter, c.x = value would invoke the setter and del c.x the deleter.

The use of the property is to set an attribute value for your class. The first parameter sets the method that gets the value of the property, the second parameter sets the method for setting the property value, the third parameter sets the method to delete the property value, and the fourth parameter is the document. C.x invokes the method of the first argument, c.x = value calls the second method, and Del c.x calls the third method. Such

What do you do with the property in 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.