Python Programming: TUPLE Data Type

1. What is TUPLE?

Tuple is similar to the list, the difference is that the elements of the tuple cannot be modified, so using tuple can make the code more secure. The tuple uses small brackets, lists the square brackets. TUPLE and LIST can index, slice, while tuple is also an unity list.

2. How to create tuple?

The tuple creation is very simple, only need to add an element in parentheses and use a comma. Let’s create a tuple in several different ways.

TUPLE1=# Create an empty group

Tuple2=(1,) # 不 加加, tuple2 type is integer

TUPLE3=(‘tony’, ‘Tom’, 33, 55) # 元组 can also be different types of data

Tuple4="Hello", "Good", "better", "best" # No need to be brackets

Type (x) uses this built-in method to determine what type of data current X is

3. How do I access the value in Tuple?

TUPLE3 [-1] indicates reverse reading, reading a countdown first element

Tuple3 [0: -2] indicates that reading from the first element to the second element

4. How to modify the value in the TUPLE?

The element value in the tuple is not allowed, but we can get a new TUPLE to achieve the purpose of modifying by intercepting the reputation.

Tuple7 [0]="hi" # This modification is not allowed

Del tuple7 [0] # This deletion is also not allowed.

Del tuple7 # This type of deletion does not exist after taking operation.

5. What are the operators of the TUPLE?

This section is the same as the List of the previous chapter.

6. What are the common built-in functions ofTUPLE?

The TUPLE built-in function is the same as the List, and is only part.

Note: The tuple method can convert a list into a tuple type, see the tuple8 tuple in the figure.

Summary: Today, the definition characteristics of TUPLE this type of data are mainly told and the difference between the difference, creation, value, update deletion, the use of operators, and the simple use of commonly used functions.