Python string isprintable() method
Python String isprintable() Method
Description
The isprintable() method checks whether all characters in a string are printable. All letters (A-Z, a-z), numbers, and symbols are printable. Escape characters are not printable.
Syntax
var.isprintable()
Parameters
None
Return Value
This method returns true if all characters in the string are printable. Otherwise, it returns false.
Example
The following example demonstrates the use of the isprintable() method.
var = "Hello Python"
var1 = var.isprintable()
print ("Raw string:", var)
print ("Is it printable?:", var1)
var = "HellotPython"
var2 = var.isprintable()
print ("Raw string:", var)
print ("Is it printable?:", var2)
var = "HellobPython"
var3 = var.isidentifier()
print ("Raw string:", var)
print ("Is it printable?:", var3)
When you run this program, it will produce the following output −
Original string: Hello Python
Is it printable?: True
Original string: Hello Python
Is it printable?: False
Original string: HellPython
Is it printable?: False
Here, “t” is the escape character for tab, and “b” is the escape character for backspace.