Python:class VS Instance

Source: Internet
Author: User

In CPP we think that class is the definition of an object, and that instance is a concrete instance of this object, so class has no real meaning to provide direct operation. But in Python is a completely different world, Python adhering to a part of the Java every is Object design concept, that the class itself certainly can not let go, so the class here is also an example, but only this one, can not be arbitrarily derived, Naturally we think of the Singlton in CPP, to a large extent the role of the two is the same, but from the design concept of the two are completely different, of course, in Python also has a good sington implementation.

To emphasize that Python's class and instance are completely different systems, from the definition of variables to the invocation of a function, are not the same, from the definition of variables, defined in class is the class of member, in the __init__ is instance itself, From the function, if there is @classmethod is the function of class, nothing is the general instance. And the first parameter of the two functions is different, one is self and the other is CLS, perhaps this also explains why Python must add a self to the Menber function, because there is another CLS that needs to be differentiated.


Python:class VS Instance

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.