Python (variable, method) difference between object-oriented (member, Static, Class)

Source: Internet
Author: User

A static method is a method that uses the @staticmethod decoration, and the parameter table does not require the self or the CLS to access the class member variable

The default method is self, a member method, access to private variables and methods (via SELF.XXX), or access to a class method or variable (through the class name ). Method name or variable name )

Class methods are decorated with @classmethod, and self is not required in the parameter table, but CLS parameters are required to be associated with the current class. You cannot access member variables and methods, but you can access class methods or class variables by cls.xxx

Here is a summary of some of the great gods on the Web:

Static member methods: Cannot access class properties, instance properties, equivalent to an independent method, can understand and the class does not matter, just with the class added a scope, such as: A class, there are three kinds of encryption algorithm, you can consider the static method;

Class member methods: The ability to access class properties, unable to access instance properties, it is important to note that Python is a dynamic language, unlike C + +, instances can be dynamically added properties, that is, the properties of the instance and the properties of the class are not necessarily the same

Python (variable, method) difference between object-oriented (member, Static, Class)

Related Article

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.