# How can I do Python Tuple Slicing?

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

Slicing operator can be used with any sequence data type, including Tuple. Slicing means separating a part of a sequence, here a tuple. The symbol used for slicing is ‘:’. The operator requires two operands. First operand is the index of starting element of slice, and second is index of last element in slice+1. Resultant slice is also a tuple.

>>> T1=(10,50,20,9,40,25,60,30,1,56)
>>> T1[2:4]
(20, 9)

Both operands are optional. If first operand is missing, slice starts from beginning. If second operand is missing, slice goes upto end.

>>> T1=(10,50,20,9,40,25,60,30,1,56)
>>> T1[6:]
(60, 30, 1, 56)
>>> T1[:4]
(10, 50, 20, 9)

Updated on 20-Feb-2020 11:27:57