Python Practice › Tuple Programs › Program 20

Slice a tuple

EasyTuple Programs · 20 of 70

Write a Python program to slice a tuple.

Advertisement
Input
(5, 7, 3, 4, 9, 0, 2)
Output
(5, 7, 3)
(3, 4, 9)
(2, 0, 9, 4, 3, 7, 5)

Approach

  1. t[start:stop] works like list slicing.

Solution

Python
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)
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More tuple programs

← All 70 Tuple Programs