Methods in Python Use the

Source: Internet
Author: User
Tags instance method
#Python其实有3个方法, the static method (Staticmethod), the class method (Classmethod), and the instance method, are as follows: Class Foo:    def bar (self):        # CLS is an instance        of the current object Print ("bar")    @staticmethod    def STA ():        print ("123")    @staticmethod    def stat (A1,A2):        print ( A1,A2)    @classmethod    def classmd (CLS):        #cls is the class name        print (CLS)        print ("Classmd") #静态方法执行, Static methods do not have to create Object Foo (). Bar () #需要创建对象调用Foo. STA () #直接用类调用Foo. Stat (in) #--------------------------------------print ( FOO.CLASSMD ()) #-------class method, saved in the class, called directly by the class, the CLS current Class-------------------------------# # #应用场景 "" If you need to save some values in the object, when you perform some kinetic energy You need to use the normal method in the object. Static methods are used when values in any object are not required. """

  

Methods in Python Use the

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.