Editor

Predict the Output: sort() vs sorted()

Beginner · Predict the output · from Python Sorting: sort(), sorted(), Key Functions, and Custom Order

From the lesson: Python Sorting: sort(), sorted(), Key Functions, and Custom Order

Imagine your bookshelf at home. Books are scattered everywhere - some by title, some by color, some shoved in sideways. Finding anything takes forever.

Read the lesson

Read the code below carefully. What will it print? Remember the key difference between sort() and sorted().

Type the exact output.

nums = [3, 1, 4, 1, 5]
result = nums.sort()
print(result)
print(nums)

More Sorting exercises

All Python exercises · 50 practice problems · Data Structures quiz