Python's built-in data types Tuple articles

Tuple is an immutable list. Once you create a tuple, you can not change it. This modified a bit like const variables in C ++. The following excerpt Dive Into Python:

Tuple list faster than the operation speed. If you define a constant set of values, and the only use it to do it is to continue to iterate through it, use a tuple instead of the list. 
If the data does not need to modify the "write protection" can make the code more secure. Use tuple instead of a list like having an implied assert statement, 
explained that the data is constant. If these values must be changed, it is necessary to perform tuple list conversion (need to use a special function). Tuples can be used as a key in a dictionary, but the list does not work. In fact, things are more complicated than this.
Dictionary key must be immutable. Tuple itself can not be changed, but if you have a list of tuple, it is considered to be variable, and
used as a dictionary key is unsafe. Only string, integer, or other tuple dictionary for security before they can be used as dictionary key.
Tuple can be converted into a list, and vice versa. Built-in tuple function receives a list, and returns a tuple with the same elements.
The list function takes a tuple and returns a list. In effect, tuple freezes a list, and the list thaw a tuple.

 

Reproduced in: https: //www.cnblogs.com/RainingDays/p/3503897.html

Guess you like

Origin blog.csdn.net/weixin_34395205/article/details/94538765