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

Basic useTry it yourself
print("hello".isprintable(), "line\n".isprintable(), "".isprintable())

Output

True False True
Strip unprintable charactersTry it yourself
raw = "name:\tAda\x00"
print(repr("".join(c for c in raw if c.isprintable())))

Output

'name:Ada'

Version history

VersionChange
Python 3.0Added