Question

Difference between sort() and sorted()?

Updated on June 2, 2025 | By Learnzy Admin | 👁️ Views: 320 students

Solution
✔ Verified

1. sort()

  • Method used only on lists
  • Sorts the list in place (modifies the original list)
  • Does not return the sorted list (returns None)
  • More memory efficient because it doesn’t create a new list
  • numbers = [3, 1, 4, 2]
    numbers.sort()
    print(numbers)  # Output: [1, 2, 3, 4]
    

2. sorted()

  • Built-in function that works on any iterable (like lists, tuples, strings, sets, etc.)
  • Returns a new sorted list
  • Does not change the original data
  • numbers = [3, 1, 4, 2]
    new_list = sorted(numbers)
    print(numbers)     # Output: [3, 1, 4, 2]
    print(new_list)    # Output: [1, 2, 3, 4]
    

 

Was this solution helpful? 39
Click here to download practice questions on Python Lists

More Questions on Python Lists

Question 1

How to check if two lists are equal?


View solution
Question 2

Find common elements in two lists


View solution
Question 3

Is Python list mutable?


View solution
Question 4

How to remove duplicates from a list?


View solution
Question 5

What is a list in Python?


View solution
Question 6

How to remove an element from a list?


View solution
Question 7

What is the difference between append() and extend()?


View solution