Python Tutorial Python Advanced Python References Python Libraries

Python String - isprintable() Method



The Python isprintable() method is used to check whether all characters of the string are printable or not. It returns true when all characters of the string are printable, else returns false. Few of the non-printable characters are - \n line feed, \t tab feed, \s space feed and \r carriage return etc.

Syntax

string.isprintable()

Parameters

No parameter is required.

Return Value

Returns True if all characters of the specified string are printable, else returns False.

Example:

In the example below, isprintable() method is used to check whether all characters of the string are printable or not.

MyString = "Hello World!"
print(MyString.isprintable())

MyString = "Hello\nWorld"
print(MyString.isprintable())

The output of the above code will be:

True
False

❮ Python String Methods