Python Tuples in are similar to lists , The difference is
(1) Elements of tuples cannot be modified or deleted , But it can be sliced and connected .
(2) Tuples use braces , The list uses brackets
(3) Single element tuple A comma must be added to the definition (,)
# Define a tuple
t1=(20,10,'abc','Python')
print(t1)
(20, 10, ‘abc’, ‘Python’)
# Get elements by index
print(t1[0])
20
print(t1[1:3])
(10, ‘abc’)
# Concatenation of tuples ,+
t2=(50,'Hadoop','Spark')
print(t1+t2)
(20, 10, ‘abc’, ‘Python’, 50, ‘Hadoop’, ‘Spark’)
Be careful 1: Tuple of an element , Add a... At the back “,”
Be careful 2: Arbitrary with “,” Separate sequences , Default is tuple .
Be careful 3:Python Tuples tuple() Function to convert a list to a tuple .