Computer Science
How are individual elements of tuples accessed?
Python Tuples
1 Like
Answer
The individual elements of a tuple are accessed through their indexes given in square brackets as shown in the example below:
Example:
tup = ("python", "tuple", "computer")
print(tup[1])
Output
tuple
Answered By
1 Like
Related Questions
What are different ways of creating a tuple?
What values can we have in a tuple? Do they all have to be the same type*?
How do you create the following tuples?
(a) (4, 5, 6)
(b) (-2, 1, 3)
(c) (-9, -8, -7, -6, -5)
(d) (-9, -10, -11, -12)
(e) (0, 1, 2)
If a = (5, 4, 3, 2, 1, 0) evaluate the following expressions:
(a) a[0]
(b) a[1]
(c) a[a[0]]
(d) a[a[-1]]
(e) a[a[a[a[2]+1]]]