isprintable() method of str class in Python

The isprintable() method returns True if all the characters of a string are printable, else it returns False. Examples of non-printable characters include u001C - line feed, u000C - Form feed and others.

Str Updated 19 Nov 2019 1 min read

Method Name

isprintable

Method Signature

isprintable()

Parameters

None

Return Value

True – if no non-printable characters found. False otherwise.

Overview

  • The method isprintable()checks whether all the characters of a Python string literal are printable. If all the characters it returns True.
  • If one or more characters of a string literal is non-printable isprintable()returns False.
  • For empty strings the method returns True.

Example

python
# Example Python program that tests whether

# a string literal is composed fully of printable characters

testString      = "Token\u001C";

printability    = testString.isprintable();

print("The string has all of its characters printable:");

print(printability);

Output

Output
The string has all of its characters printable:

False