Copy specific elements from one tuple to a new tuple


The program is written in Python. It creates a tuple t1 containing 10 elements (10, 20, 30, 40, 50, 60, 70, 80, 90, 100). Then, the program creates another tuple t2 by slicing t1 from index 2 to index 8 (excluding index 8). The slicing operation returns a new tuple that contains the elements from t1 at indices 2, 3, 4, 5, 6, and 7. Finally, the program prints the tuple t2 using the "print" function.

Source Code

t1 = (10,20,30,40,50,60,70,80,90,100)
t2 = t1[2:8]
print(t2)

Output

(30, 40, 50, 60, 70, 80)

Example Programs