The “isspace Python function” is used to check if there are only whitespace characters in the string. Python String isspace() will return boolean value, if there is space only then true else return False
Syntax
1 |
string.isspace() |
Return Value
True
if all characters in the string are whitespace (space) characters else False
.
isspace Python function Example
Single space
1 2 |
str1 = " " print(str1.isspace()) |
Output: True
Multiple spaces text
If all the characters in the text are whitespaces it will return true.
1 2 |
str1 = " " print(str1.isspace()) |
Output: True
Q: Python isspace not working if there are char and space in String?
Output: It will work but return value will be false.
1 2 |
str1 = " e " print(str1.isspace()) |
Output: False
Do comment if you have any question 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.