My friends, for reprint please indicate the source: blog.csdn.net/jiangjunsho…

Disclaimer: During the teaching of artificial intelligence technology, many students asked me some python related questions, so in order to let students master more extended knowledge and better understand AI technology, I asked my assistant to share this Python series of tutorials, hoping to help you! Since this Python tutorial is not written by me, it is not as funny and boring as my AI teaching. But its knowledge points or say in place, also worth reading! PS: if you don’t understand this article, please read the previous article first. Step by step, you won’t feel difficult to learn a little every day!

Tuples are very similar to lists, except that tuples cannot be modified in place (they are immutable) and are usually written in parentheses (not square brackets). Although tuples do not support any method calls, they have most of the properties of a list. Let’s take a quick look at its properties.

  • An ordered collection of any objects

Similar to strings and lists, a tuple is a collection of objects that are placed in order (that is, their contents remain in left-to-right order). As with lists, objects of any kind can be contained.

  • Access by offset

Like strings and lists, elements in a tuple are accessed by offsets rather than keys. They support all offset-based operations. For example, indexes and sharding.

  • Is of the immutable sequence type

Like strings, tuples are immutable, and they do not support in-place modification operations that apply to lists. Like strings and lists, tuples are sequences that support many of the same operations.

  • Fixed length, heterogeneous, arbitrary nesting

Because tuples are immutable, they cannot grow or shrink without making a copy. Tuples, on the other hand, can contain other composite objects (for example, lists, dictionaries, and other tuples), thus supporting nesting.

  • An array of object references

Like a list, elements in a tuple contain references to objects. Tuples store access points (references) to other objects, which makes indexing tuples relatively fast.

We’ll learn more about tuples step by step later!