Question:

What will be the output of the following Python code?
a = [1, 2, 3]
print(a[::-1])

Show Hint

The slice [::-1] is the "Pythonic" way to reverse a list or string. It’s concise, fast, and very common in coding interviews!
Updated On: May 11, 2026
  • [1, 2, 3]
  • [3, 2, 1]
  • Error
  • None
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation


Step 1: Understanding the Concept:

This question tests your knowledge of "Slicing" in Python. Slicing allows you to access a specific range or order of elements in a sequence like a list or string.

Step 2: Detailed Explanation:

The syntax for slicing is [start:stop:step].
• In the code a[::-1], the start and stop values are omitted, which means Python considers the whole list.
• The step value is -1. A negative step means the list is traversed backwards.
• Therefore, a[::-1] creates a new list starting from the last element and moving to the first.

Step 3: Final Answer:

The output will be the reversed list: [3, 2, 1].
Was this answer helpful?
0
0