str.isspace
Check that the string is not empty and contains only whitespace.
Python 3.13
str.isspace()Return value
True or False; False for an empty string.
Examples
Space, tab and newline
Python 3.13
print(' \t\n'.isspace())True
An empty string and a string with a letter
Python 3.13
print(''.isspace(), ' a '.isspace())False False
Details
Whitespace includes the space, the tab \t, the newline \n and other invisible separators. An empty string gives False, so the check "empty or only spaces" is easier to write as not text.strip().
