ValueError: too many values to unpack (expected 2)
时间: 2023-09-22 20:09:14 浏览: 41
This error message typically occurs when you are trying to unpack an iterable (such as a list, tuple, or dictionary) into multiple variables, but the number of items in the iterable does not match the number of variables you are trying to unpack into.
For example, if you try to unpack a tuple with three values into two variables:
```
a, b = (1, 2, 3)
```
you will get a "ValueError: too many values to unpack (expected 2)" because there are three values in the tuple but only two variables to assign them to.
To fix this error, make sure that the number of variables you are unpacking into matches the number of items in the iterable. If you don't need all the values, you can use the underscore (_) to indicate that you are not interested in some of them:
```
a, b, _ = (1, 2, 3)
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)