- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
How can I do Python Tuple Slicing?
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)
- Related Articles
- How can I append a tuple into another tuple in Python?
- How can I use Multiple-tuple in Python?
- How can I convert Python strings into tuple?
- How can I subtract tuple of tuples from a tuple in Python?
- How can I convert Python tuple to C array?
- How can I create a non-literal python tuple?
- How can I represent python tuple in JSON format?
- How I can convert a Python Tuple into Dictionary?
- How can I convert a Python tuple to string?
- How can I create a Python tuple of Unicode strings?
- How can I remove items out of a Python tuple?
- How can I define duplicate items in a Python tuple?
- How can I convert a Python tuple to an Array?
- How I can dump a Python tuple in JSON format?
- How can I do "cd" in Python?