Static member variables, instance member variables, static methods, class methods, instance methods for Python

Source: Internet
Author: User

Static member variables (class variables) and normal member variables (instance variables)

Static member variables can only be obtained through the class name. Variable name, instance member variable, referenced by the instance. Variable name obtained.

When an instance assigns a value to a static member variable, the instance

Python is a dynamically typed language with no special flags distinguishing between static member variables and ordinary member variables

If you use the class name. Member variable that member variable is now a static member variable (class variable)

If you use an instance. member variable that member variable is now a normal member variable (instance variable)


Static methods, class methods, instance methods

An instance method, a normal method in a class, called by an instance

Class methods, methods that are decorated by @classmethod, class objects, and instances can call class methods

Static methods, methods that are decorated by @staticmethod, class objects and instances can call static methods, and static methods do not affect any instances

The difference between an instance method and a class method is that the first argument to the instance method is self (the instance itself), and the first parameter of the class method is the CLS (Class object province)

Note: The class object and the instance object here mean the type (class name)---classobj
Type (instance name)-instance

Static member variables, instance member variables, static methods, class methods, instance methods for Python

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.