@property adorners are actually a bit boring, it's not necessary to take them out alone as a knowledge point, although it can turn the method into a property that makes the get and set methods work better, but it destroys the simplicity of Python (not the simplicity of the code but the syntax).
Here's why I'm saying this.
First, look at a use property.
class Student (object): @property def testname (self): return Self.name @testname. Setter def testname (self,name): == "Alex"print(s.testname)
The result is:
/system/library/frameworks/python.framework/versions/3.4/bin/python3/users/lsf/pycharmprojects/py3project/ Test3.pyalexprocess finished with exit code 0
It does look good, but in fact Python's built-in __getattr__ and __setattr__ are ways to turn the method into a property feature.
class Stu (object): def pass def __setattr__ (Self,name,value): Self. __dict__ [Name] = __getattr__ return Span style= "color: #000000;" > Self.names = Stu () s.name = " Span style= "color: #800000;" >alex print (s.name)
The result is of course:
/system/library/frameworks/python.framework/versions/3.4/bin/python3/users/lsf/pycharmprojects/py3project/ Test3.pyalexprocess finished with exit code 0
Advanced features of Python 10: Boring @property