Learn Python on the road ....

Source: Internet
Author: User

about properties and methods in class classesdef __init__ (self, variable): A method that is automatically called when the class is defined as an objectdef __call__ (self, variable): This is to call the method of the class directly when the function is called, generally the object. Method () call, which is called by the object ()def __str__ (self, variable): This is a method that the object is directly printed by default call is usually a print (object) to usedef __getattr__ (self, variable): This is called when an object calls its properties, there is no error . Add this method to change the error to call the GetAttr methoddef __setattr__ (self, variable): This is the method that will be called when the object property is set. This method is easy to error, write a method to pay attention to the dead loop property: Use to define an attribute such as name at the end of the class, and then the name is "Properties" (Method 1, Method 2, Method 3, "comment")  Method 1: Calling this property calls Method 1, which equals the Read property call Method 1Method 2: The method that is called when writing to this property 2 this method equals Write property Method 2Method 3: When you delete this property, Method 3 is called, which equals the Delete attribute Method 3       

Learning Python on the road ....

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.