Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




isprintable( ) FUNCTION


isprintable( ) Function


The isprintable( ) Function is used to check if all the letters in the String are printable or not.


Example :


x = "Hello World"
if x.isprintable():
    print("All the letters in the String are printable")
else:
    print("No! Not all the letters in the String are printable")


Output :



  All the letters in the String are printable

In the above code, we have declared a String 'Hello World' that has all printable characters.


x = "Hello World"

java_Collections

So, to check, if all the letters in the String are printable, we have used 'isprintable( )' function.


if x.isprintable():
    print("All the letters in the String are printable")
else:
    print("No! Not all the letters in the String are printable")

And in this case, all the letters in the String printable. So, we got the below output.


All the letters in the String are printable

Similarly, let us look at the next example.


Example :


x = "Hello\nWorld"
if x.isprintable():
    print("All the letters in the String are printable")
else:
    print("No! Not all the letters in the String are printable")


Output :



  No! Not all the letters in the String are printable

In the above code , we have declared a String 'Hello\nWorld' that has an escape character i.e. '\n', which is not printable.


x = "Hello\nWorld"

java_Collections

So , to check, if all the letters in the String are printable, we have used 'isprintable( )' function.


if x.isprintable():
    print("All the letters in the String are printable")
else:
    print("No! Not all the letters in the String are printable")

And in this case , all the letters in the String are not printable. So, we got the below output .


No! Not all the letters in the String are printable