Computer Science
Carefully read the given code fragments and figure out the errors that the code may produce.
t = ('a', 'b', 'c', 'd', 'e')
print(t[5])
Python Tuples
4 Likes
Answer
Output
IndexError: tuple index out of range
Explanation
Tuple t has 5 elements starting from index 0 to 4. t[5] will throw an error since index 5 doesn't exist.
Answered By
2 Likes
Related Questions
What will be stored in variables a, b, c, d, e, f, g, h, after following statements ?
perc = (88,85,80,88,83,86) a = perc[2:2] b = perc[2:] c = perc[:2] d = perc[:-2] e = perc[-2:] f = perc[2:-2] g = perc[-2:2] h = perc[:]
What does each of the following expressions evaluate to? Suppose that T is the tuple containing :
("These", ["are" , "a", "few", "words"] , "that", "we", "will" , "use")
T[1][0: :2]
"a" in T[1][0]
T[:1] + [1]
T[2::2]
T[2][2] in T[1]
Carefully read the given code fragments and figure out the errors that the code may produce.
t = ('a', 'b', 'c', 'd', 'e') t[0] = 'A'
Carefully read the given code fragments and figure out the errors that the code may produce.
t1 = (3) t2 = (4, 5, 6) t3 = t1 + t2 print (t3)