CBSE Class 11 Computer Science Question 46 of 88

Tuples and Dictionary — Question 11

Back to all questions
11
Question

Question 11

Write a Python program to combine first 3 elements and last 3 elements from a tuple.

T1 = ('a', 1, 2, 3, 4, 'b', 'c', 'book', 10)

Output should be:

('a', 1, 2, 'c', 'book', 10)

Answer
T1 = ('a', 1, 2, 3, 4, 'b', 'c', 'book', 10)
first_three = T1[:3]
last_three = T1[-3:]
result = first_three + last_three
print(result)
Output
('a', 1, 2, 'c', 'book', 10)