2(viii)
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.