# Put the resulting property value on the method @property
# on the method of setting the property value @ property name. Setter
# Two methods have the same name and are all property names
#先写 @property Write the @ property name again. Setter
class Person (object):
def __init__ (self,name,age):# When defining object properties, private properties are not added __
Self.name = Name
Self.age = Age
@property#相当于getName () method
def name (self):
return Self.__name# But when you return, you still want to self.__ the private property name
@name. Setter#相当于setName () method
def name (Self,name):
If Len (name) > 6:
Print ("illegal")
Else
Self.__name = Name# When assigning a value also self.__ property name = property name
P1 = person ("312,358", 13)
Print (P1.name)
""
Summary: 1, when defining object properties, do not need to add __ in Object properties
2. To define the @property equivalent to the Get method first
3. Define the @ property name again. Setter equals Set method
4, when the object is called directly is the object name. Property name
‘‘‘
Note: This method sets the private property, and the @ property name is called when the object instance initialization assignment is created. Setter Method Filter Data
Python Private Property @property method