---
title: "list.sort"
space: "Student Handbook"
url: "https://portal.cs17.org/student-handbook/python-manual/lists/sort"
updated: "2026-10-05"
---

Puts a list in order.

## Synopsis

```python
items.sort()
items.sort(reverse=True)
sorted(items)
```

## Description

`items.sort()` changes the list itself. `sorted(items)` leaves it alone and returns a new, sorted list.

Strings sort by character code, so capital letters come before lowercase ones.

## Parameters

| Name | Meaning |
| --- | --- |
| `reverse` | `True` sorts from largest to smallest. Optional. |

## Return value

`sort` returns `None`. `sorted` returns a new `list`.

## Example

```python
nums = [3, 1, 2]
nums.sort()
print(nums)
nums.sort(reverse=True)
print(nums)
words = ["banana", "Apple", "cherry"]
print(sorted(words))
print(words)
```

It prints:

```text
[1, 2, 3]
[3, 2, 1]
['Apple', 'banana', 'cherry']
['banana', 'Apple', 'cherry']
```

## Common mistake

```python
items = [3, "a", 1]
items.sort()
```

Python stops with:

```text
TypeError: '<' not supported between instances of 'str' and 'int'
```

Python cannot say whether a number comes before a string. Keep one type per list.

## See also

[min](/student-handbook/python-manual/built-in-functions/min), [max](/student-handbook/python-manual/built-in-functions/max), [list.append](/student-handbook/python-manual/lists/append)

[list.sort in the Python documentation](https://docs.python.org/3/library/stdtypes.html#list.sort)
