Python standard library: Built-in function property (Fget=none, Fset=none, Fdel=none, Doc=none)

Source: Internet
Author: User

This function is a property that sets a member of a class. The parameter fget is the property value that gets the class member , and the parameter fset is the property value that sets the class member;Fdel is the delete class member; parameter doc is the document string that sets the property. Through this function, we can implement the method of hiding the class member variable, which is the requirement of object-oriented encapsulation.

Example:

#property () class Foo:    def __init__ (self):        self._x = None    def getx (self):        return self._x    def setx ( Self, value):        self._x = value    def delx (self):        del self._x    x = Property (Getx, Setx, Delx, "I ' m the ' x ' prop Erty. ")    foo = foo () foo.x = 2000print (foo.x) del foo.x

The resulting output is as follows:

2000




Cai Junsheng qq:9073204 Shenzhen

Python standard library: Built-in function property (Fget=none, Fset=none, Fdel=none, Doc=none)

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.