What is the output of the following Python code?
list_1 = []
list_1.append([(1, 2, 3), {1: (4, 5, 6, 7)}, [8, 9]])
print(list_1[0][1][1])
a) TypeError: 'int' object is not subscriptable
b) (8,9]
c) (4, 5, 6, 7)
d) IndexError: list index out of range
Answers
Answered by
57
The output is (4, 5, 6, 7)
Answered by
63
Answer:
Option (c) is correct one.
Explanation:
"[(1, 2, 3), {1: (4, 5, 6, 7)}, [8, 9]]" will be appended as one element such that list_1= [ [(1, 2, 3), {1: (4, 5, 6, 7)}, [8, 9]] ].
Now when you use "list_1[0][1][1]". First you're calling the 0 indexed element of list_1 which is " [(1, 2, 3), {1: (4, 5, 6, 7)}, [8, 9]] ",
The second number [1] denoted that you're calling the 1 indexed element of element on list_1's 0 index which is "{1: (4, 5, 6, 7)}" and the last [1] means you're asking for the the value with key = 1 in the dictionary that is on 1st index of 0th index of list_1 which is (4, 5, 6, 7).
Similar questions
Math,
2 months ago
Math,
2 months ago
English,
2 months ago
Math,
5 months ago
Math,
5 months ago
Social Sciences,
11 months ago
Social Sciences,
11 months ago