Python method calls between the self. method and the Cls= class name; cls. method, what is the difference between the two ways?

Source: Internet
Author: User
I see tornado has a chat room demo, the class Messagemixin method calls using the Cls= class, CLS. method, the way to self. The method seems to be no different from the previous invocation, do not know whether there is any deep difference between the two methods?

Reply content:

An article I've written.

What is method?

function is a piece of code that can be called by name, and we can pass parameters in to get the return value. All parameters are explicitly passed in the past.
method is the combination of function and object. When we call a method, some parameters are implicitly passed in the past. This is detailed below.

Instancemethod
In [5]: class Human(object):   ...:     def __init__(self, weight):   ...:         self.weight = weight   ...:     def get_weight(self):   ...:         return self.weight   ...:     In [6]: Human.get_weightOut[6]: 
  
  
Suppose there is a Class C, and O is an object of Class C, then
Although there is a slight difference in the implementation process, the results say that
O.method (ARG, ...) is equivalent to C.method (O, arg, ...)

Have not understood the question, first Google and ask first, two kinds of ways what is the difference?

By the way, to help you to correct the case, no thanks.

  • 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.