isspace Python function | Check if a string has space

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



Return Value

True if all characters in the string are whitespace (space) characters else False.

isspace Python function Example

Single spaced

str1 = " "

Output: True

Multiple spaces text

If all the characters in the text are whitespaces it will return true.

str1 = "    "

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  "

Output: False

Do comment if you have any questions and suggestions.

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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.