Code with the error

times = [52, 47, 60]
ordered = times.sort()
print(ordered[0])

Error message (Python 3.12, last line)

TypeError: 'NoneType' object is not subscriptable

Corrected code

times = [52, 47, 60]
ordered = sorted(times)
print(ordered[0])

Output

47

Common causes

  • The result of list.sort(), list.reverse() or list.append() is saved to a variable.
  • A function has no return, so it gives None.
  • A function returns a value only in one branch of if.
  • dict.get() did not find the key and returned None.

Practise in the course

Lesson: Lists

Frequently asked questions

What does subscriptable mean?

A value you can use with square brackets, such as a list, a string or a dictionary.

What is the difference between sort() and sorted()?

sort() reorders the list itself and returns None; sorted() returns a new sorted list.