Question:medium

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 30, 2026
  • [1, 2, 3]
  • [3, 2, 1]
  • Error
  • None
Show Solution

The Correct Option is B

Solution and Explanation

Step 1: Understanding the Concept:
This question tests the knowledge of Python's "Slice" notation. The syntax for a slice is \( [start:stop:step] \).
Step 2: Detailed Explanation:
In the expression a[::-1]:
- The start index is empty: This defaults to the beginning or end of the list depending on the sign of the step.
- The stop index is empty: This defaults to the end or beginning of the list.
- The step is set to -1: A negative step indicates that the list should be traversed in reverse order.
When the step is -1 and start/stop are omitted, Python effectively reverses the entire sequence.
Sequence: [1, 2, 3]
Reversed: [3, 2, 1]
Step 3: Final Answer:
The print statement will output the reversed list [3, 2, 1].
Was this answer helpful?
0


Questions Asked in CUET (UG) exam