Article From:https://www.cnblogs.com/daqingzi/p/9373111.html

Class objects: class names (such as Student)

Instance object: object created by class (xiaoming=Student ())

Class properties can be shared by class objects and instance objects.

Instance attributes can only be owned by instance objects, and class objects cannot be owned.

 

PS:If you modify class attributes outside the class, you must refer to it through the class object. If you refer to it through the instance object, it actually produces a new instance attribute, modifies the instance attribute without affecting the class attribute, and if you refer to it through the instance object, it refers to the newly generated attribute.

If the instance attribute is deleted, the class attribute continues to be referenced.

 

Class methods:

Class methods can be referenced by instance objects and class objects, using the decorator @classmethod, in parentheses (cls), and modifying class attributes.

Static method:

Static methods can also be referenced by instance objects and class objects.@staticmethod,Parentheses do not need parameters.

propertyDecorator (attribute method)

When do attribute methods generally apply?

Attribute method, usage: instance. Attribute (which is equivalent to an instance object calling the method, but is displayed in an attributed way)

Look at the following example:

The results are as follows:

The above code is the same. If you delete it, call mmmm.mkj again.

The result is:

Note: the attribute method brackets are self.

 

Leave a Reply

Your email address will not be published. Required fields are marked *