cool hit counter python zero-based learning (VIII)_Intefrankly

python zero-based learning (VIII)

Topic: tuple type Tuple in python


There are many similarities between tuple types and list types, and the differences are highlighted below in the introduction.

A tuple, too, consists of a number of elements, separated by commas. The difference is that the tuple is wrapped in parentheses, not mentioned in the previous article, and an empty list can be created with the following command.

Create a list with only one element.

Create empty tuple command.

Here comes the difference, when creating a tuple with only one element, you have to write an extra comma after that element otherwise you're not creating a tuple type, what exactly is it? Students can try it out for themselves.

Element access and list slicing

As with the list operation.

Basic tuple operations

As with the list operation.

Tuple deletion

The biggest difference between a tuple and a list is that a tuple object is immutable and cannot add an element, delete an element, modify an element, or insert an element into an existing tuple, but it can be deleted by deleting the entire tuple, which is also possible with lists.

Tuple manipulation functions

Additional functions for tuple operations can be viewed with the help function.

Additional points

Supplement I

In addition to the creation of a tuple as described above, any number of comma-separated elements placed together are, by default, of the tuple type.

Supplement II

The same element content above returns False, but for lists, the previous post returns True, I guess because the tuple element is an immutable result.

Supplement III

As you have seen, the difference between a tuple and a list is that a tuple object is immutable once it is defined. That means that all the functions that a tuple can do, a list can do, so why should a tuple exist at all? One reason is that it is more efficient to access the tuple due to its immutability; the other is that because of immutability, it is possible to avoid mishandling for manipulating data that is write-protected.

Supplement IV

The tuple can be split using the following command.

Dynamic display.

This concludes the article, please feel free to leave comments if you need to discuss anything.

Don't stand around if you can do it.

1、Database Indexing Learning Sharing
2、Why did the programmer keep laughing while the police uncle was giving his statement
3、A number of new products of Zongren Technology were presented at the 2017 Shanghai Creative Industries Expo and received considerable attention
4、Tips for using the old version of Book Catcher
5、Blockchains slow bull needs real killer apps on the ground

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送