The “isspace Python function” is used to check if there are only whitespace characters in the string. Python String isspace() will return a boolean value, if there is space only then true else return False
Syntax
string.isspace()
Return Value
True
if all characters in the string are whitespace (space) characters else False
.
isspace Python function Example
Single spaced
str1 = " " print(str1.isspace())
Output: True
Multiple spaces text
If all the characters in the text are whitespaces it will return true.
str1 = " " print(str1.isspace())
Output: True
Q: Python isspace not working if there are char and space in String?
Output: It will work but the return value will be false.
str1 = " e " print(str1.isspace())
Output: False
Do comment if you have any questions and suggestions.
Note:
IDE: PyCharm 2020.1 (Community Edition)
macOS 10.15.4
Python 3.7
All Python Examples are in Python 3, so it may change its different from python 2 or upgraded versions.