?
What is the output of the following code:
What is the output of the following code:
my_list = [3, 1, 4, 1]
print(sorted(my_list))
print(sorted(my_list))
Answer & Solution
Correct Answer:
Option
A
The correct answer is Option A: [1, 1, 3, 4].
The sorted() function in Python is used to sort the elements of an iterable in ascending order. When you pass the list [3, 1, 4, 1] to the sorted() function, it sorts the elements and returns a new list with the elements sorted in ascending order. Therefore, the output will be [1, 1, 3, 4].
The sorted() function in Python is used to sort the elements of an iterable in ascending order. When you pass the list [3, 1, 4, 1] to the sorted() function, it sorts the elements and returns a new list with the elements sorted in ascending order. Therefore, the output will be [1, 1, 3, 4].
Join the Discussion
Login to post a comment or share your explanation.
Login