Python ValueError: not enough values to unpack (expected 3, got 1) - Solution and Explanation
This error occurs when you try to unpack too few values from an iterable, such as a tuple or list.
For example, let's say you have a tuple with three elements:
my_tuple = (1, 2, 3)
If you try to unpack this tuple into only one variable, you will get the 'not enough values to unpack' error:
x = my_tuple
Output:
ValueError: not enough values to unpack (expected 3, got 1)
To fix this error, make sure you are unpacking the correct number of values from the iterable. In the above example, you can fix the error by unpacking the tuple into three variables:
x, y, z = my_tuple
This will assign the values 1, 2, and 3 to the variables x, y, and z respectively.
原文地址: https://www.cveoy.top/t/topic/nKTi 著作权归作者所有。请勿转载和采集!