TypeError
TypeError: cannot unpack non-iterable NoneType object
Traceback
Traceback (most recent call last):
File "main.py", line 1, in <module>
first, second = [3, 1, 2].sort()
TypeError: cannot unpack non-iterable NoneType objectWhat causes this error
Tuple unpacking was used on an object that is not iterable. This commonly happens when a function returns None (like list.sort()) and the return value is unpacked.
How to fix it
Check the return value type of functions before unpacking. Many list methods return None because they modify in-place. Separate the operation from the unpacking.
Code that causes this error
first, second = [3, 1, 2].sort()
Fixed code
data = [3, 1, 2] data.sort() first, second = data[0], data[1]
About TypeError
This error occurs when you try to use tuple unpacking (destructuring) on an object that does not support iteration. The most common trigger is unpacking the return value of a function that returns None — for example, a function that modifies data in-place and implicitly returns None. Python expects the right side of an unpacking assignment to be an iterable (list, tuple, string, generator, etc.), and when it finds a non-iterable type, it raises this TypeError.
The error message specifies which type was encountered (often NoneType, int, float, or bool). This error is especially common with list methods like `.sort()`, `.append()`, `.extend()`, and `.reverse()`, all of which return None. Dictionary methods like `.update()` also return None.
The fix is to ensure the right side of the unpacking is actually an iterable, often by calling the function separately and then unpacking the result.
Common scenarios
Performing operations between incompatible types like strings and integers
Calling methods that return None and chaining operations on the result
Passing the wrong number or type of arguments to a function
Using bracket notation on objects that do not support indexing