Characteristics of object-oriented class members

Source: Internet
Author: User

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

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.