hhutoo判断集合不为空
时间: 2024-04-30 18:24:26 浏览: 12
你可以使用以下方式判断一个集合是否为空:
```python
my_set = set()
if not my_set:
print("集合为空")
else:
print("集合不为空")
```
在上面的代码中,我们首先创建了一个空集合 `my_set`。然后,我们使用 `not` 关键字来判断集合是否为空。如果集合为空,则 `not my_set` 的值为 `True`,这意味着集合为空。否则,如果集合不为空,则 `not my_set` 的值为 `False`,这意味着集合不为空。最后,我们使用 `if` 语句来根据集合是否为空来打印相应的消息。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)