?
What is the output of the following code:
What is the output of the following code:
my_list = [1, 2, 3]
print(list(reversed(my_list)))
print(list(reversed(my_list)))
Answer & Solution
Correct Answer:
Option
A
The correct answer is Option A: [3, 2, 1].
The reversed() function in Python is used to reverse the elements of an iterable. When you pass the list [1, 2, 3] to the reversed() function and then convert the result to a list using list(), it returns a new list with the elements reversed, resulting in [3, 2, 1].
The reversed() function in Python is used to reverse the elements of an iterable. When you pass the list [1, 2, 3] to the reversed() function and then convert the result to a list using list(), it returns a new list with the elements reversed, resulting in [3, 2, 1].
Join the Discussion
Login to post a comment or share your explanation.
Login