掃二維碼與項(xiàng)目經(jīng)理溝通
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢(xún)/運(yùn)營(yíng)咨詢(xún)/技術(shù)建議/互聯(lián)網(wǎng)交流
python 中的isspace()函數(shù)有助于檢查字符串中的所有字符是否都是空白字符。如果字符串中充滿空白字符(制表符、空格、換行符等),則該函數(shù)返回 true。)否則返回 false。

**string.isspace()**
isspace()參數(shù):isspace()方法不接受任何參數(shù)。
isspace()返回值返回值始終是布爾值。如果字符串為空,函數(shù)返回假。
| 投入 | 返回值 | | 所有空白字符 | 真實(shí)的 | | 至少一個(gè)非空白字符 | 錯(cuò)誤的 |
isspace()方法的示例isspace()在 Python 中是如何工作的? string = ' \t'
print(string.isspace())
string = ' a '
print(string.isspace())
string = ''
print(string.isspace())
輸出:
True
False
False 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 
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢(xún)/運(yùn)營(yíng)咨詢(xún)/技術(shù)建議/互聯(lián)網(wǎng)交流