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
str.strip
Returns a copy of the string with leading and trailing whitespace removed. If chars is given, removes any leading/trailing characters that appear in the chars set (not a prefix/suffix — it is a character set).
str.isalpha
Returns True if the string is non-empty and every character is an alphabetic Unicode letter. Digits, whitespace, and punctuation all return False.
str.isdigit
Returns True if every character in the string is a digit and the string is non-empty. Includes Unicode digit characters like superscripts (²) but excludes signs, decimal points, and fractions like ½.