CBSE Class 11 Computer Science Question 46 of 82

Lists in Python — Question 11

Back to all questions
11
Question

Question 8(d)

What will be the output of the following statement?

list1 = [1, 2, 3, 4, 5]
list1[len(list1)-1]
Answer
Output
[1, 2, 3, 4, 5]
Explanation

In the given code, list1 is initialized as [1, 2, 3, 4, 5]. The len(list1) returns the number of elements in the list, which is 5. The len(list1) - 1 evaluates to 4 (i.e., 5 - 1). The list1[len(list1) - 1] accesses the element at index 4, which is 5. However, since the result is not assigned to any variable or printed, it has no effect on the list.