Python Glossary Русский

all Python 3Strings (str)function

str.isspace

character checks

True if the string is non-empty and all characters are whitespace.

Syntax

s.isspace()

Whitespace here is not just space, \t and \n but Unicode ones too, such as the non-breaking \xa0 — text scraped from the web often looks blank because of those. When you only need to know that the input carries nothing meaningful, not s.strip() is shorter and safer: it also covers the empty string, where isspace() returns False.

Examples

print('   '.isspace())    # → True
print(' \t\n'.isspace())  # → True
print(''.isspace())       # → False

See also

Open in the full glossarydocs.python.orgReport an inaccuracy