min() arg is an empty sequence
时间: 2024-05-10 17:21:06 浏览: 26
This error occurs when you try to use the `min()` function on an empty sequence, such as an empty list, tuple, or set. The `min()` function is used to find the minimum value of a given sequence. However, if the sequence is empty, there is no minimum value to return, and the function will raise an error.
Here is an example of how this error can occur:
```python
my_list = []
min_value = min(my_list)
```
In this case, `my_list` is an empty list, so there is no minimum value to return. The `min()` function will raise the following error:
```
ValueError: min() arg is an empty sequence
```
To avoid this error, you should always check if the sequence is empty before using the `min()` function. Here is an example of how to do this:
```python
my_list = []
if len(my_list) > 0:
min_value = min(my_list)
else:
min_value = None
```
In this case, we check if the length of `my_list` is greater than 0 before using the `min()` function. If the list is empty, we set `min_value` to `None` instead of raising an error.
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)
![](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)