Question DSA-ARR-0004
EasyWhat is the output of this code?
a = [1, 2, 3, 4, 5]
print(a[::-1])
- A.
[5, 4, 3, 2, 1]
- B.
[5]
- C.
Show answer and explanation
Answer: A
The slice [::-1] steps backwards through the list, giving a reversed copy.
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 = [1, 2, 3, 4, 5]
print(a[::-1])
[5, 4, 3, 2, 1]
[5]
Answer: A
The slice [::-1] steps backwards through the list, giving a reversed copy.
[1]
[1, 2, 3, 4, 5]