The isprintable() method in Python is used to check if all characters in a string are printable. It returns True if all characters are printable, otherwise it returns False.
Parameter Values
This function does not accept any parameters.Return Values
The isprintable() method returns a bool value: True or False.
How to Use isprintable() in Python
Example 1:
The isprintable() method returns True if all characters in the string are printable or the string is empty, otherwise it returns False.
text = 'Hello, world!'\nprint(text.isprintable())
Example 2:
This method also returns True if the string only contains white spaces.
text = ' '\nprint(text.isprintable())
Example 3:
If the string contains non-printable characters, it will return False.
text = 'Hello\nworld!'\nprint(text.isprintable())