KnowledgeBoat Logo
|

Computer Science

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)

Python Tuples

4 Likes

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)

Answered By

1 Like


Related Questions