Simple comprehension and summary of Python classes and objects

Source: Internet
Author: User

Class:

Class, which is an abstraction of a group of objects with the same properties and methods.

A stricter definition of a class is a cohesive package that consists of a particular kind of meta-data. It describes the rules of behavior of some objects, which are known as instances of the class. Classes have interfaces and structures. Interfaces describe how methods interoperate with classes and their instances, and structs describe how data in an instance is divided into multiple properties.


Object:

An object is an instantiation of a class that refers to something specific.

Object: An object has its own state, behavior, and unique identity; the structure and behavior of all objects of the same type are defined in their common class.

State: Includes properties that are already present in the object (usually defined in the class), plus the current property values that the object has (often dynamic)

Behavior (behavior): Refers to how an object affects the outside world and is influenced by the outside world, and manifests itself as the change of the state of the object and the transmission of information.

Identity: Refers to an object that has a property that differs from all other objects. (essentially the address of an object created in memory)


Classes and objects have properties and methods

In cases where the referenced data type is immutable, the class property is not affected by the object property, which means that the property of the object changes without affecting the class property.

However, the class property affects the object property because the object is instantiated by the class, the Class property is changed, and the object properties are changed.

If a property refers to a mutable data type, either a class or an instance of a property change can affect the other party.


If you add a class property, the instance object also adds a property of the same name and data. Adding properties to an instance object does not affect class properties.

Simple comprehension and summary of Python classes and objects

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.