python判断字符串是否为空

python判断字符串是否为空方法总结
 

方法一:使用字符串长度判断
如果 len(s) ==0 则字符串为空
方法二:isspace判断是否字符串全部是空格
如果s.isspace() 为True 字符串为空,否则非空
方法三:直接判断是否为空
if s == '' 字符串为空,否则非空
方法四:使用strip()函数判断字符串是否为空
strip() 方法用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列。
if not s.strip():
    字符串为空
else:
    字符串非空
 

猜你喜欢

转载自blog.csdn.net/jccc39/article/details/105752645