どうも、ちょげ(@chogetarou)です。
文字列が空白のみかどうか確認する方法を紹介します。
方法

文字列が空白のみかどうか判定するには、isspace()を使います。
具体的には、対象の文字列からisspace()を呼び出します。
result = text.isspace()
isspace()は、呼び出した文字列が空白のみならばTrue、空白のみで無いならばFalseを返します。
使用例
text1 = "H e l l o, W o r l d"
text2 = " "
result1 = text1.isspace()
result2 = text2.isspace()
print(result1)
print(result2)
出力:
False
True
コメント