Python 3 reference · String Methods
Python String isprintable() Method
Return True if every character is printable, or the string is empty. Newlines and tabs are not printable.
Python 3 Since 3.0
Syntax
str.isprintable()
Return value
True or False.
Examples
print("hello".isprintable(), "line\n".isprintable(), "".isprintable())
Output
True False True
raw = "name:\tAda\x00"
print(repr("".join(c for c in raw if c.isprintable())))
Output
'name:Ada'
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
str.isspace()· Return True if every character is whitespace (spaces, tabs, newlines) and the string isn't empty.str.isascii()· Return True if the string is empty or every character is ASCII (code points 0–127).- Python Strings · tutorial