1. Attribute keywords in a class @property
Access attributes
2. Keyword @end.setter
Setting properties
3. Normal methods need to add () to execute the method
4. Features, do not need to add () to execute, equivalent to access by the field, the method is forged into a kind of fields, but the disadvantage is not to pass parameters.
classProvice:#static fields, in classCountry =" China" def __init__(self, name): Temp="XXX" #normal field, in Object (Self is object)Self.name =name#common methods, in class defShow (self):Print("Show") #static method, no self in (), but can pass value #static methods belong to classes and are called through classes. @staticmethoddefXO (BK):Print("XO") Print(BK)#class Method@classmethoddefXxoo (CLS):Print("Xxoo", CLS)#Common Methods defStart (self): temp="%s is SB"%Self.namereturnTemp#attribute to forge a method into a field. #Access Attributes@propertydefEnd (self): temp="%s is smart"%Self.namereturnTemp#Setting Properties@end. SetterdefEnd (self, value):Print(value) self.name=Valueobj= Provice ("Alex") Ret1= Obj.start ()#Add () to execute the Start methodRet2 = Obj.end#without Add (), you can execute the end method. Equivalent to being accessed through a field. But the disadvantage is that parameters cannot be passed. #When you need to set the attribute. You need to follow the method of defining an end. Because there is no place to accept parameters. #keyword @end.setterObj.end ="XXX" #print "xxx" in the Settings featurePrint(Obj.end)#first execute the Access attribute (obj.end), get the value of the return value, temp, and then execute (print (obj.end))
Characteristics of object-oriented class members