Robotics & Artificial Intelligence
What will be the output of the code given below:
my_list = [10, 20, 30, 40, 50]
print("The number is ", my_list[-2])
Python List Manipulation
1 Like
Answer
The number is 40
Working
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.
Answered By
3 Likes
Related Questions
What is the Turing Test, and what role does it play in AI?
What is problem scoping in the context of an AI project?
What will be the output of the code given below:
import numpy as np arr = np.array([1, 2, 3, 4, 5]) print(arr[2])What will be the output of the code given below:
text = "Python Programming" print(text[7:])