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.
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
- Print the list first to see its length:
print("4 5".split()). - Make sure the program input has every value the program asks for.
- Read the values into a list and check
len(values)before unpacking them.