Python's object and type understanding

Source: Internet
Author: User

1, excerpt from the Python documentation 3.5.2 part of the explanation

Objects is Python ' s abstraction for Data. All the data in a Python program are represented by objects or by relations between Objects. (in a sense, and in conformance to Von Neumann's model of a "stored program computer," code was also represented by objects .)

The object is a Python abstraction of the Data. All data in a Python program is represented by a relationship between an object or an Object. (in a sense, The code is also represented by the object, in a way that conforms to the von Neumann's "stored program computer" model).

Every object has an identity, a type and a Value. An object's identity never changes once it has been created; You may think of it as the Object's address in Memory. The ' is operator compares the identity of both objects; the id() function returns an integer representing its identity .

Each object has an identity, a type, and a Value. Once the identity of the object is created, it will not change; You can think of it as an object address in Memory. The ' is ' operator compares the identities of two objects; The ID () function returns an integer representing its Identity.

An Object's type determines the operations that the object supports (e.g., "does it has a Length?") and also defines the Possible values for objects of the that Type. The type () function returns an object ' s type (which was an object itself). Like it identity, an object's type is also unchangeable.

The type of the object determines the operations that the object supports (for example, "does it have a Length?") "), and also defines the possible values for the type Object. The type () function returns the kind of an object (it is an object itself). As with its identity, the type of the object is Immutable.

2, the pyhtml explanation:

Object

class Object      The most base type

Type

class type (object)      type (object_or_name, bases, Dict)      , the object's type      Type (name, bases, dict), a new type

As can be seen from the above three graphs, object Obeject is the most basic type, and it is a holistic abstraction of the Data. A type is a slightly more specific abstraction than object objects, saying it is specific because it already has a factor that refines more specific abstractions from Object objects, which is why type (int), type (float), type (str), type The types (list), type (tuple), type (set), and so on are all type, which is why instance (type, Object) and instance (object, Type) are true, That is, type types are the whole concept of types such as int, float, and so On. so, Why Issubclass (type, Object) is true, and Issubclass (object, Type) is flase? As you can see from the second picture, the type is a subclass of object, so the former is true and the latter is False.

If you look at these issues from a more fundamental perspective, you need to documentation-->3 from Python. Data model-->3.1 objects,values and types find out why [please refer to the official Python standard library], which can be seen from the standard library:

    • object is a Python abstraction of data, which is a centralized representation of the data in a Python Program.
    • Each object has an identity, a type, and a Value.
    • The type of the object determines the operations that the object Supports.
    • The values of some objects can be changed. Objects whose values can be changed are called mutable objects, and objects whose values cannot be changed after creation are called immutable Objects.

therefore, from the perspective of the overall design system of python, It is the first object, then the identity, type and value, followed by the operation of the object, and so on, which explains the results of Figure 3 is the reason for the Formation.

Python's object and type understanding

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.