Signup/Sign In

Python String isprintable()

Python String isprintable() method is used to check if any given string is printable or not.

  • The isprintable() method is an inbuilt method in python used for String Handling.

  • If all characters in a string are printable or if there is an empty string in both these cases, this method returns true otherwise, this method returns false.

  • Here any string is printable if its alphabets are in uppercase, lowercase, or if a string contains digits, punctuations, or space.

  • With the help of this method, we can count the number of non-printable characters of a string too.

Python String isprintable(): Syntax

Below we have a basic syntax of String isprintable() in Python:


Note: In the above syntax, the string is used to denote the value of the string that is needed to be checked.

Also, it is clear from the above syntax, that this method does not contains any parameters. This method throws an error if any parameter will be passed to it.

Python String isprintable(): Returned Values

For the returned value there are two cases:

  • This method returns true in the case if all characters in a string are printable.

  • Otherwise, in all other cases, this method returns false.

Python String isprintable(): Basic Example

Below we have an example to show the working of the string isprintable() function in python:

a = "Hell0"
b = "!@#$%^&*("
c = "Hello Boy "
d = "Yes \n No"
e = "1234 !@#@!%^ abcd"
print("String: ", a, " printable: ", a.isprintable())
print("String: ", b, " printable: ", b.isprintable())
print("String: ", c, " printable: ", c.isprintable())
print("String: ", d, " printable: ", d.isprintable())
print("String: ", e, " printable: ", e.isprintable())

The Output for the same is given below:

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

Time for a Live Example!

Let us see a live example below where isprintable() function is used in different situations:


In this tutorial, we have learned about python isprintable() method which returns true in the case if the string is printable otherwise returns false.