Examveda

What is the output of the following code:
my_list = [3, 1, 4, 1]
print(sorted(my_list))

A. [1, 1, 3, 4]

B. [3, 1, 4, 1]

C. [4, 3, 1, 1]

D. [1, 3, 1, 4]

Answer: Option A

Solution (By Examveda Team)

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].

This Question Belongs to Python Program >> Python Built In Functions

Join The Discussion

Related Questions on Python Built In Functions