The String isprintable() method returns True if the string is empty or if all characters in the string are printable. Otherwise, it returns False.
Syntax
my_string.isprintable()isprintable() Parameters
Python String isprintable() method does not take any parameters.
isprintable() Return Value
Python String isprintable() method returns:
Trueif all characters in the string are printable or if the string is empty.Falseif the string contains at least one non-printable character.
Examples
Example 1: Check if a String is printable with isprintable()
The isprintable() method returns True if all characters in the string are printable characters.
my_str = 'Tutorial Reference'
result = my_str.isprintable()
print(result) # Output: Trueoutput
TrueThe isnumeric() method returns False if at least one character is not printable.
For example, string with line feed \n and tab \t is not printable:
my_str = '\tTutorial\nReference'
result = my_str.isprintable()
print(result) # Output: Falseoutput
FalseExample 2: Check if an Empty String is printable with isprintable()
An empty string is considered a printable string.
my_str = ''
result = my_str.isprintable()
print(result) # Output: Trueoutput
True