Python sorted() vs list.sort() Explained

Python gives you two common ways to sort values:

  • sorted()
  • list.sort()

They look similar, but they do not behave the same way.

The main difference is simple:

  • Use sorted() when you want a new sorted result
  • Use list.sort() when you want to change the original list

This matters a lot for beginners, especially when list.sort() returns None and causes confusion.

Quick answer

numbers = [3, 1, 2]

new_list = sorted(numbers)   # returns a new sorted list
numbers.sort()              # sorts the original list in place

Use sorted() when you want a new result. Use list.sort() when you want to change the existing list.

What this page helps you decide

  • Use sorted() to get a new sorted list
  • Use list.sort() to sort an existing list in place
  • Understand why list.sort() returns None
  • See when each option is better for beginner code

What sorted() does

sorted() is a built-in Python function.

It:

  • returns a new list
  • does not change the original data
  • works with many iterable objects, not just lists

That includes:

  • lists
  • tuples
  • strings
  • sets
  • other iterable objects

Example: sorted() keeps the original list unchanged

numbers = [3, 1, 2]

result = sorted(numbers)

print("original:", numbers)
print("sorted result:", result)

Output:

original: [3, 1, 2]
sorted result: [1, 2, 3]

The important part is that numbers stays the same.

If you want a full function-focused explanation, see Python sorted() function explained.

What list.sort() does

sort() is a method that belongs to lists.

It:

  • changes the original list directly
  • only works on lists
  • returns None

Example: list.sort() changes the original list

numbers = [3, 1, 2]

numbers.sort()

print(numbers)

Output:

[1, 2, 3]

After calling numbers.sort(), the list itself is changed.

For a method-specific reference page, see Python list.sort() method.

Main difference at a glance

Here is the core difference:

  • sorted(iterable) → returns a new sorted list
  • my_list.sort() → changes my_list directly

Side-by-side example

numbers = [5, 2, 4]

a = sorted(numbers)
print("numbers after sorted():", numbers)
print("a:", a)

numbers.sort()
print("numbers after sort():", numbers)

Output:

numbers after sorted(): [5, 2, 4]
a: [2, 4, 5]
numbers after sort(): [2, 4, 5]

So:

  • sorted() keeps the original data unchanged
  • sort() is useful when you do not need the original order anymore

When to use sorted()

Use sorted() when:

  • you want to keep the original list unchanged
  • your data is not a list
  • you want to store the result in a new variable
  • you want clearer code that is easy to read

Example: sorting a tuple

numbers = (4, 1, 3, 2)

result = sorted(numbers)

print(result)
print(type(result))

Output:

[1, 2, 3, 4]
<class 'list'>

Notice that sorted() can sort a tuple, but the result is a list.

If you are still learning list behavior, Python lists explained for beginners is a helpful next step.

When to use list.sort()

Use list.sort() when:

  • you already have a list
  • you want to update that list directly
  • you do not need the original order anymore
  • you want a simple in-place change

Example: sorting one list directly

names = ["Charlie", "Alice", "Bob"]

names.sort()

print(names)

Output:

['Alice', 'Bob', 'Charlie']

This is a good choice when you only need the list in sorted form and do not care about keeping the old order.

If your goal is the task itself, see How to sort a list in Python.

reverse and key work with both

Both sorted() and list.sort() support:

  • reverse=True for descending order
  • key=... for custom sorting rules

The sorting behavior is very similar. The main difference is still whether you get a new list or change the original one.

Example: descending order

numbers = [3, 1, 2]

print(sorted(numbers, reverse=True))

numbers.sort(reverse=True)
print(numbers)

Output:

[3, 2, 1]
[3, 2, 1]

Example: case-insensitive sorting

words = ["Banana", "apple", "Cherry"]

print(sorted(words, key=str.lower))

words.sort(key=str.lower)
print(words)

Output:

['apple', 'Banana', 'Cherry']
['apple', 'Banana', 'Cherry']

Using key=str.lower tells Python to compare words in lowercase form.

For more advanced custom sorting, especially with dictionaries, see How to sort a list of dictionaries in Python.

Beginner mistakes to watch for

These are the most common problems beginners run into.

Mistake 1: Assigning list.sort() to a variable

This is probably the most common one.

numbers = [3, 1, 2]

result = numbers.sort()

print(result)
print(numbers)

Output:

None
[1, 2, 3]

Why this happens:

  • numbers.sort() sorts the list in place
  • it does not return the sorted list
  • so result becomes None

Mistake 2: Expecting sorted() to change the original list

numbers = [3, 1, 2]

sorted(numbers)

print(numbers)

Output:

[3, 1, 2]

sorted(numbers) creates a new sorted list, but here the result is not saved anywhere.

Correct version:

numbers = [3, 1, 2]

new_numbers = sorted(numbers)

print(new_numbers)

Mistake 3: Trying to call sort() on a tuple or string

text = "python"
text.sort()

This will fail because strings do not have a sort() method.

sort() only works on lists.

If you need to sort other iterable objects, use sorted(). This is easier to understand if you know what an iterable is, so you may also want to read iterators and iterable objects explained.

Mistake 4: Forgetting that sorted() always returns a list

text = "cab"
result = sorted(text)

print(result)
print(type(result))

Output:

['a', 'b', 'c']
<class 'list'>

Even though the original value was a string, the result is still a list.

Common causes of confusion

Beginners usually mix these up for one of these reasons:

  • confusing a function with a method
  • not knowing that sort() changes the list in place
  • assigning the result of list.sort() to a variable
  • trying to use sort() on non-list data types
  • expecting sorted() to preserve the original data type, such as tuple or string

If something is not behaving the way you expect, these quick checks can help:

print(my_list)
print(sorted(my_list))
result = my_list.sort(); print(result)
print(type(my_data))
help(sorted)
help(list.sort)

These are useful for checking:

  • whether your original list changed
  • what sorted() returns
  • whether sort() returned None
  • what type of object you are working with

Simple rule to remember

Use this rule:

  • Need a new sorted result: use sorted()
  • Need to change one list directly: use list.sort()

For many beginners, sorted() feels easier because it is more explicit and does not silently change the original list.

FAQ

Which is better for beginners, sorted() or list.sort()?

sorted() is often easier to understand because it returns a new result and does not change the original data.

Why does list.sort() return None?

Because it changes the list directly instead of creating and returning a new sorted list.

Can sorted() sort a tuple?

Yes. It can sort any iterable, but it returns a list.

Can I use sort() on a string?

No. sort() is a list method. Use sorted(string) if needed.

Do sorted() and sort() both support descending order?

Yes. Both support reverse=True.

See also