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

 Live Demo

#!/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]

Updated on: 28-Jan-2020

8K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements