
- 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
Accessing Values of Tuples in Python
To access values in tuple, use the square brackets for slicing along with the index or indices to obtain value available at that index.
Example
#!/usr/bin/python tup1 = ('physics', 'chemistry', 1997, 2000); tup2 = (1, 2, 3, 4, 5, 6, 7 ); print "tup1[0]: ", tup1[0]; print "tup2[1:5]: ", tup2[1:5];
Output
When the above code is executed, it produces the following result −
tup1[0]: physics tup2[1:5]: [2, 3, 4, 5]
- Related Articles
- Accessing nth element from Python tuples in list
- Accessing Values of Strings in Python
- Accessing Values of Lists in Python
- Accessing Values of Dictionary in Python
- Combining tuples in list of tuples in Python
- Count tuples occurrence in list of tuples in Python
- Safely Accessing Deeply Nested Values In JavaScript
- Remove duplicate tuples from list of tuples in Python
- Addition of tuples in Python
- Accessing Attributes and Methods in Python
- Summation of tuples in list in Python
- Remove tuples from list of tuples if greater than n in Python
- Python program to find Tuples with positive elements in List of tuples
- Updating Tuples in Python
- Compare tuples in Python

Advertisements