美图齐众专注资阳网站设计 资阳网站制作 资阳网站建设
资阳网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

创新互联Python教程:Pythonisspace()

python 中的isspace()函数有助于检查字符串中的所有字符是否都是空白字符。如果字符串中充满空白字符(制表符、空格、换行符等),则该函数返回 true。)否则返回 false。

 **string.isspace()** 

isspace()参数:

isspace()方法不接受任何参数。

isspace()返回值

返回值始终是布尔值。如果字符串为空,函数返回假。

| 投入 | 返回值 | | 所有空白字符 | 真实的 | | 至少一个非空白字符 | 错误的 |

Python 中isspace()方法的示例

示例isspace()在 Python 中是如何工作的?

 string = '   \t'
print(string.isspace())

string = ' a '
print(string.isspace())

string = ''
print(string.isspace()) 

输出:

 True
False
False 

示例 2:如何在 Python 中使用isspace()

 string = '\t  \n'
if string.isspace() == True:
  print('String full of whitespace characters')
else:
  print('String contains non-whitespace characters')

string = '15+3 = 18'

if string.isspace() == True:
  print('String full of whitespace characters')
else:
  print('String contains non-whitespace characters.') 

输出:

 String full of whitespace characters
String contains non-whitespace characters 

网站标题:创新互联Python教程:Pythonisspace()
分享网址:http://www.zsjierui.cn/article/ccicece.html

其他资讯