The @classmethod in Python

Source: Internet
Author: User
Tags instance method

[Email protected] is a function modifier, which means that the next is a class method, and for the usual we see is called the instance method. The first parameter of the class method is CLS, and the first argument of the instance method is self, which represents an instance of the class.

2. The normal object method requires at least one self parameter, which represents the Class object instance

3. Class methods have the class variable CLS incoming, so that some related processing can be done with the CLS. And with subclass inheritance, when the class method is called, the passed-in class variable CLS is a subclass, not a parent class. For a class method, it can be called through a class, like C.F (), a bit like a static method in C + +, or it can be called through an instance of the class, like C (). f (), here C (), written so that it is an instance of the class.

So when we write the method of the class, if we want to pass 2 parameters, when we define the method in the class to write three to add a CLS or self where the CLS can point out the method with @classmethod, self can point out the unused @classmethod method

The @classmethod in Python

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.