Python String isprintable() Method

The isprintable() method is used to check if all characters in a string are printable i.e., they can be visibly displayed on the screen. Printable characters include letters, digits, punctuation marks, and standard whitespace, but exclude non-visible escape characters such as tab (\t), newline(\n), carriage return (\r), etc.

Syntax

string.isprintable()

Parameters

No parameters.

Return Value

Returns True if all characters in a string are printable or if the string is empty.

Returns False if there are any non-printable characters in the string.

Example

Check if a String is Printable

print("Hello".isprintable())        # True 
print("Hello World".isprintable())  # True (contains space)
print("123".isprintable())          # True
print("Hello\nWorld".isprintable()) # False (contains newline)
print("Hello\tWorld".isprintable()) # False (contains tab)
print("".isprintable())             # True (empty string)