Q59
Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order, which of the following methods should be used?
A.
reverse(l)
B.
list(reverse[(l)])
C.
reversed(l)
D.
list(reversed(l))
AnswerAnswer: Option D
Solution
Answer: Option D
Solution:
To print a list in reverse order in Python, you can use the reversed() function, which returns an iterator that yields items in reverse order. However, to display it as a list, you need to convert the iterator back to a list using the list() function. Therefore, list(reversed(l)) is the correct method to print the list l in reverse order.