Question DSA-ARR-0006
EasyWhat is the output of this code?
a = [10, 20, 30, 40]
print(a[-2])
- A.
Error
- B.
20
- C.
Show answer and explanation
Answer: D
Negative indices count from the end in Python: a[-2] is the second-last element, 30.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Arrays question
What is the output of this code?
a = [10, 20, 30, 40]
print(a[-2])
Error
20
Answer: D
Negative indices count from the end in Python: a[-2] is the second-last element, 30.
40
30