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 lessonRead 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
- Sort a List of NumbersBeginner
- Sort Words by LengthIntermediate
- Fix the Bug: Case-Sensitive SortingIntermediate
- Sort Students by GradeIntermediate
- Sort by Multiple CriteriaAdvanced
All Python exercises · 50 practice problems · Data Structures quiz