Check a String is Printable in Python

  • Post category:String

In this article, you will see how to check a string is printable in Python. A printable string is a string that contains only printable characters. The string isprintable() method returns True if all characters in the string are printable, otherwise False.

Step 1: Create a string

str = "\n"
print("str = ", str)
print("str type = ", type(str))

Step 2: Check if a string is printable

if all(c.isprintable() for c in str):
    print("Not Printable")


str =  

str type =  <class 'str'>
Not Printable

Free resources to learn advanced skills: AiHints and CodeAllow