新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonisspace()
python 中的isspace()函數(shù)有助于檢查字符串中的所有字符是否都是空白字符。如果字符串中充滿空白字符(制表符、空格、換行符等),則該函數(shù)返回 true。)否則返回 false。

**string.isspace()**
isspace()參數(shù):
isspace()方法不接受任何參數(shù)。
isspace()返回值
返回值始終是布爾值。如果字符串為空,函數(shù)返回假。
| 投入 | 返回值 | | 所有空白字符 | 真實(shí)的 | | 至少一個(gè)非空白字符 | 錯(cuò)誤的 |
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 分享題目:創(chuàng)新互聯(lián)Python教程:Pythonisspace()
文章轉(zhuǎn)載:http://www.5511xx.com/article/ccicece.html


咨詢
建站咨詢
