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)