static methods in class

Source: Internet
Author: User

To use a static method in a class, precede the class member function with the @staticmethod tag to indicate that the following member function is a static function. The advantage of using static methods is that you do not need to define an instance to use this method. In addition, multiple instances share this static method.

# Spec: own members to access, in addition to the methods in the class, methods in the class to access the object # through the class to access the: Class property, static method # through the object to access the: Object properties, Methods in the class # static methods exist in the sense that you do not need to create an object to execute the methodclassAObject): Country='China'def __init__ (self,place): Self.place=Place def weather (self): print (Self.place+'Sunny Day') @staticmethod def temperature (): Print ('accessing static methods by Class ...') @staticmethod def func (A, B): Print ('static methods can pass parameters:', A, b) cc= A ('Changchun') Cc.weather () print (A.country) a.temperature () A.func (1,2)

static methods in class

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.