What will be the output of the code given below:

ICSE Class 10 Robotics & AI PYQ · 2025 Specimen · Section A

2(viii)1 Mark · 2025 · Section A · 2025 Specimen

What will be the output of the code given below:

my_list = [10, 20, 30, 40, 50]
print("The number is ", my_list[-2])
Show SolutionHide Solution↓
The number is 40

In Python, negative indexing is used to access elements from the end of a list. The index -1 refers to the last element, and -2 refers to the second last element. In the list [10, 20, 30, 40, 50], the second last element is 40, so it is printed.

← Previous questionNext question →

Browse the free Robotics & AI sample bank