Python Practice › Tuple Programs › Program 20
Slice a tuple
Write a Python program to slice a tuple.
Input
(5, 7, 3, 4, 9, 0, 2)
Output
(5, 7, 3) (3, 4, 9) (2, 0, 9, 4, 3, 7, 5)
Approach
t[start:stop]works like list slicing.
Solution
t = (5, 7, 3, 4, 9, 0, 2)print(t[:3])print(t[2:5])print(t[::-1])Output
(5, 7, 3) (3, 4, 9) (2, 0, 9, 4, 3, 7, 5)
Learn the concept
New to this topic? Read the lesson, then come back.
1 thought on “Slice a tuple”