Python String isprintable() Method

Determines whether string contains printable characters


The isprintable() method returns TRUE if the string is empty or all characters in it are printable.

It returns FALSE if the string contains at least one non-printable character.

Carriage return \r , line feed \n and tab \t are examples of nonprintable characters.

A simple space character ' ' (0x20, ASCII space) is considered printable.




Example: Check if all characters in the string are printable

S = 'Hello, World!'
x = S.isprintable()
print(x)    # True

Example: Line feed \n and tab \t are nonprintable characters

S = '\tHello,\nWorld!'
x = S.isprintable()
print(x)    # False

Example: Empty string is considered printable

S = ''
x = S.isprintable()
print(x)    # True