Q. What does the Python code: x = [1, 2, 3]; print(x[::-1]) output?

A
[1, 2, 3]
B
[3, 2, 1]
C
[3, 1]
D
Error
Solution:

The slice notation [::-1] with a step of -1 reverses the list, so [1, 2, 3] becomes [3, 2, 1].

Entri PDF Icon

Get Question Bank

Strengthen Your Practice with our comprehensive question bank.

Entri Contact Image

Get Expert Advice for Free: Register for Your Free Consultation Now!