Python Glossary Русский

Python 3.0+Strings (str)function

str.isprintable

character checks

True if the string is empty or all characters are printable (no \t, \n, …).

Syntax

s.isprintable()

Printability here follows Unicode: everything in the Other and Separator categories is non-printable, with the plain ASCII space as the single exception. So 'a b' is True, while a string holding a non-breaking space \xa0 is False. Note also that the empty string returns True, unlike nearly every other is* check.

Examples

print('abc 123'.isprintable())  # → True
print('a\tb'.isprintable())     # → False
print(''.isprintable())         # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy