Call between Python methods. What is the difference between self. Method and cls = Class Name; cls. method?

Source: Internet
Author: User
I can see that tornado has a chat room demo. The cls class is used for calling MessageMixin methods; cls. method, change to self. the method seems to be no different from the previous call method. I wonder if there is any deep difference between the two methods? I can see that tornado has a chat room demo. cls = Class is used for calling methods like MessageMixin; cls. method, change to self. the method seems to be no different from the previous call method. I wonder if there is any deep difference between the two methods? Reply: an article I wrote

What is method?

Function is a piece of code that can be called by name. We can pass parameters to get the return value. All parameters are passed explicitly.
Method is the combination of functions and objects. When we call a method, some parameters are implicitly passed. The following describes in detail.

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 Class c, and o is the object of class c, then
Although the execution process is slightly different,
O. method (arg,...) is equivalent to c. method (o, arg ,...)

If you have any questions you don't understand, Google and question first. What are the differences between the two methods?

By the way, you have corrected the case. Thank you.

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.