Python 判断是否空值
时间: 2023-12-05 19:39:42 浏览: 46
以下是Python中判断空值的方法:
```python
# 判断字符串是否为空
a = ''
if not a:
print('a是空字符串')
# 判断列表是否为空
b = []
if not b:
print('b是空列表')
# 判断字典是否为空
c = {}
if not c:
print('c是空字典')
# 判断元组是否为空
d = ()
if not d:
print('d是空元组')
# 判断集合是否为空
e = set()
if not e:
print('e是空集合')
# 判断变量是否为None
f = None
if f is None:
print('f是None')
```
注意,Python中的空值包括空字符串、空列表、空字典、空元组、空集合和None。判断空值时,可以使用not关键字或is None语句。