Python Series Reflection

Source: Internet
Author: User

First, static methods (Staticmethod) and class methods (Classmethod)

Class method: There is a default parameter CLS, and can be called directly with the class name, you can interact with class properties (that is, you can use class properties)

static method: Let the method in the class be called directly by the class, just like the normal calling function

The same point of a class method and a static method: All can be called directly by the class, without the need to instantiate

The difference between a class method and a static method:

The class method must have a CLS parameter representing the class, and you can use the Class property

Static methods do not require parameters

Binding methods: Divided into common methods and class methods

Common method: A Self object is passed in by default and can only be called by an object-------bound to an object

Class method: A CLS object is passed in by default and can be called by classes and objects (not recommended)-----bound to a class

Unbound methods: Static methods: No default parameters are set and can be called by classes and objects (not recommended)-----unbound

Class Foo:    passclass Son (Foo):    passs = Son () print (Isinstance (S,son))  #判断s是不是Son的对象print (type (s) is Son) Print (Isinstance (s,foo))  #判断s是不是Foo的对象  not accurate print (type (s) is Foo)  #type比较精准print (Issubclass (Son,foo)) # Determine son is not a subclass of Foo print (Issubclass (son,object)) print (Issubclass (foo,object)) print (Issubclass (int,object))

Python Series Reflection

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.