Latest Code Tutorials

Python String isprintable: The Complete Guide

A string is called printable if it contains alphabets(Uppercase and Lowercase), digits, punctuation, or space. The main application is that we can count the non-printable characters of the string which can help us to solve different kinds of problems.

Python String isprintable()

The string isprintable() method is a built-in Python method that tells us if the given string is printable() or not. It is a part of string-handling. The isprintable() method returns True if all the characters of the string are printable or empty in all the other cases it returns False.



Here the string is the string variable that is to be checked if it is printable or not.


The isprintable() method doesn’t contain any parameter and throws an error if any parameter is passed.

Return Value

The isprintable() method returns True if all the characters of the string are printable and false in all other cases.

Example programs on string isprintable() method

Example1: Write a program to show the demonstration of the isprintable() method.


h1 = "Hell0"
h2 = "!@#$%^&*("
h3 = "Hello Boy "
h4 = "Yes \n No"
h5 = "1234 !@#@!%^ abcd"
print("String: ", h1, " printable: ", h1.isprintable())
print("String: ", h2, " printable: ", h2.isprintable())
print("String: ", h3, " printable: ", h3.isprintable())
print("String: ", h4, " printable: ", h4.isprintable())
print("String: ", h5, " printable: ", h5.isprintable())


String:  Hell0  printable:  True
String:  !@#$%^&*(  printable:  True
String:  Hello Boy   printable:  True
String:  Yes 
 				   No  printable:  False
String:  1234 !@#@!%^ abcd  printable:  True

Example 2: Write a program to check two strings if they both are printable or not. If they are printed “Yes we are printable” and “Sorry we are not printable” if they are not.


h1 = "Hello boy"
h2 = "Hello\nboy"
if(h1.isprintable() and h2.isprintable()):
    print("Yes we are printable")
    print("Sorry we are not printable")


Sorry we are not printable

That’s it for this tutorial.

See also

Python string isspace()

Python string istitle()

Python string rsplit()

Python string rindex()

Python string rfind()

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.