The isprintable( ) Function is used to check if all the letters in the String are printable or not.
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")
In the above code, we have declared a String 'Hello World' that has all printable characters.
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.
Similarly, let us look at the next 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")
In the above code , we have declared a String 'Hello\nWorld' that has an escape character i.e. '\n', which is not printable.
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 .