Skip to content

Python String isprintable() Method

Check if all characters in a Python string are printable using the isprintable() method, which returns True for empty strings or strings without non-printable characters like or .

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:

  • True if all characters in the string are printable or if the string is empty.
  • False if 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: True

output

True

The 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: False

output

False

Example 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: True

output

True
Navigation