inspection

str.isspace

Returns True if the string is non-empty and every character is whitespace. Whitespace includes spaces, tabs, newlines, and other Unicode whitespace characters.

str.isspace()

Parameters

Parameter Purpose
self operates on the calling string; takes no arguments
returns bool — False for empty strings

Examples

>>> '   '.isspace()
True

spaces only

>>> '\t\n '.isspace()
True

tab, newline, and space all count

>>> ' a '.isspace()
False

any non-whitespace disqualifies

>>> ''.isspace()
False

empty string is False

Gotcha

Empty string returns False — `if not s.strip()` is a more common idiom for 'blank or empty'.

Related methods

← All Python string methods · Python built-ins