Python 3 reference · String Methods
Python String isspace() Method
Return True if every character is whitespace (spaces, tabs, newlines) and the string isn't empty.
Python 3 Since 3.0
Syntax
str.isspace()
Return value
True or False.
Examples
print(" ".isspace(), " \t\n".isspace(), "".isspace(), " a ".isspace())
Output
True True False False
lines = ["first", " ", "", "second"]
print([l for l in lines if l.strip()])
Output
['first', 'second']
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
str.strip()· Return a copy with leading and trailing characters removed: whitespace by default, or any of the characters you pass.str.isprintable()· Return True if every character is printable, or the string is empty. Newlines and tabs are not printable.- Python Strings · tutorial