Detailed introduction to Python's object and type
1. Excerpt from Python Documentation 3.5.2 Partial explanation
Objects are Python's abstraction for data. All data in a Python program is 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 is also represented by objects.)
Object is Python’s abstraction of data. All data in a Python program is represented by objects or relationships between objects. (In a sense, and consistent with von Neumann's "stored program computer" model, code is also represented by objects).
Every object has an identity, a type and a value. An object'sidentity 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 two objects; the
id() function returns an
integer representing its identity.
OperatorCompares the identities of two objects; id()FunctionReturns an integer representing their identity.
An object's types determines the operations that the object supports (e.g., “does it have a length?”) and also defines the possible values for objects of that type. The type() function returns an object's type ( which is an object itself). Like its identity, an object'stype is also unchangeable.
The type of an object determines the operations the object supports (for example, "Does it have a length?"), And also defines the possible values for objects of this type. The type() function returns the type of an object (which is the object itself). Like its identity, an object's type is immutable. 2. Pyhtml explanation:object:
class object The most base type
type:
class type(object) type(object_or_name, bases, dict) type(object) -> the object's type type(name, bases, dict) -> a new type
float), type(str), type(list), type(tuple), type(set), etc. are all types, which is why The reason why instance(type, object) and instance(object, type) are both True is that the type type is the overall concept of types such as int and float. So, why issubclass(type, object) is True, and issubclass(object, type) is False? From the second picture, that is, from the inheritance relationship, we can see that type is a subclass of object, so the former is True and the latter is False. From the perspective of the overall design of the Python language, there are objects first and then relatively specific types, that is, the design idea of giving priority to the whole over the parts.
If you look at these problems from a more essential perspective, you should find the reasons from Python Documentation-->3. Data Model-->3.1 Objects, values and types [Please refer to Python official standards Library], you can see from the standard library:- object is Python’s abstraction of data, and it is the concentrated expression of data by Python programs.
- Every object has an identity, a type and a value.
- The type of object determines the operations supported by the object.
- The values of some objects can be changed. Objects whose values can be changed are called mutable objects; objects whose values cannot be changed after creation are called immutable objects.
Therefore, from the perspective of the overall design system of Python, there are objects first, then identifiers, types and values, followed by operations on objects, etc. This also explains the meaning of Figure 3 The reason for the result.
The above is the detailed content of Detailed introduction to Python's object and type. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

Regular expressions are powerful tools for pattern matching and text manipulation in programming, enhancing efficiency in text processing across various applications.

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...
