Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How many kinds of objects are there in Python

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how many objects are there in Python". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how many objects are there in Python"?

Where does the object come from?

First of all, let's talk about where the objects in Python come from.

Typedef struct _ object {

_ PyObject_HEAD_EXTRA

Py_ssize_t ob_refcnt

PyTypeObject * ob_type

} PyObject

The underlying Python is written in C, so the orthodox Python is actually called CPython. When Windows installs Python, there must be a program called python.exe (similar to other systems) that interprets and executes Python code. The Python code here is finally converted to c code. There is a PyObject structure in the C code.

This structure is interesting and consists of two functions, one is that reference counting is used for garbage collection, and the other is a pointer to "type object", which is used to transfer to different c functions according to different types of code. In fact, this is the origin of the so-called object, because the type here will actually check the different object types defined by the python code. Once the check is passed, the corresponding function will be executed, more specifically, the corresponding data will be found in memory for processing. For example, the Python code passes a list a, and the a will eventually pass PyList_Check (a) to check whether it is the defined list type, and then do the corresponding operation.

# define PyList_Check (op)\

PyType_FastSubclass (Py_TYPE (op), Py_TPFLAGS_LIST_SUBCLASS)

For students who think object-oriented is very difficult to learn programming, you can think about it. This is just a data exchange rule defined by collusion between python and c language. It's just that there are a lot of miscellaneous rules here, so we'll talk about it later. You can collect the web de8ug.vip in advance and keep abreast of the latest developments.

How many kinds of objects are there in Python

The next step is to cooperate with Qixi Festival's performance. Let's count how many kinds of objects there are in Python.

We talked just now that there is a type in the c language corresponding to Python, which can be understood as the meaning of type. When extended to Python, there is often a word called object type. As the name implies, different objects are actually different types. All kinds of objects in our lives are classified, and if we want to deal with them in code, then classify them in the code, so that it is easy to calculate and store them.

As for how many objects there are in Python, you can start with several important built-in types. These are mainly in the stdtypes section of the official document.

The most important built-in types in Python are numerics, sequences, mappings, classes, and instances and exceptions. Translated into Putonghua is numbers, sequences, mappings, classes, examples, and exceptions. If you want to write code for a long time, it is better to remember the English name directly.

Numeric Types

Int

Float

Complex

The first is Numeric Types, which supports three kinds of data: int, float, complex (integer, floating point, complex). This is easy to understand, we have been exposed to mathematics since childhood, all kinds of calculations are inseparable from all kinds of mathematical numbers.

Sequence Types

List

Tuple

Range

Str

Binary Sequence Types-bytes, bytearray, memoryview

Set Types-set, frozenset

Then there is Sequence Types, that is, sequence types, in which list, tuple, and range are very common types of sequences, and then a more commonly used sequence about character text is taken out as str, and the binary sequence in the internal world of the computer is the most common, so the sequence type also has Binary Sequence Types, including bytes, bytearray, and memoryview.

Another special feature in the sequence is the set set, which is mainly used to find non-repetitive elements and perform mathematical set operations.

Iterator Types, Generator Types

When it comes to sequence types, there are iterators Iterator and generator Generator, which are very important for finding an element in a sequence.

Mapping Types-dict

The mapping type is a very important one in the data structure. It also has a lot of uses in a variety of programming languages, which DE8UG personally likes very much. The mapping type in Python is the dictionary dict. When doing various kinds of development, this data structure has a wide range of uses, so that we can easily store the corresponding data and quickly find the elements we need.

Other Built-in Types

Modules

Classes and Class Instances

Functions

Methods

Code Objects

Type Objects

The Null Object

The Ellipsis Object

The NotImplemented Object

Boolean Values

Internal Objects

Then there are a large number of other types. As small as Boolean,null, as big as a class, a module, it can be said that there are objects everywhere. There is no need to panic to see so many objects, according to your learning progress and use needs, encounter different objects, carefully check the corresponding properties and methods of ta.

Thank you for reading, the above is the content of "how many objects are there in Python". After the study of this article, I believe you have a deeper understanding of the question of how many objects there are in Python, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report