Write Python. Understand every error.

Open the editor

Error guide · ValueError

ValueError: not enough values to unpack (expected 3, got 2)

You gave fewer values than there are names to fill.

Example

x, y, z = "4 5".split()

What Python says

ValueError: not enough values to unpack (expected 3, got 2)

As printed by Python 3.12. Other versions may word it slightly differently.

Try this code in Py-CRAFT

Why it happens

Three names need three values, but splitting "4 5" gives only two. The message states how many values were expected and how many arrived, so compare the two numbers. Typical causes are a missing entry in the input, or a line that ends too early.

How to fix it

x, y, z = "4 5 6".split()
print(x, y, z)

Output: 4 5 6

Tips

Learn the ideas behind it

Other common errors

Share this page: