Python String isprintable() Method
The Python isprintable() method is a string method that returns True if all the characters in a string are printable, otherwise False. A printable character is one that occupies some space on the screen. Examples of non-printable characters are carriage return (\r) and line feed (\n).
Here are some examples of using the isprintable() method:
# Example 1: A simple example of printable testing using isprintable() method[^3^][1]
Given_string = 'Welcome to Python-programs'
Given_string = 'hello this is\n btechgeeks'
Given_string = ' '
print(Given_string.isprintable())
# Prints True
# Prints False
# Prints True
# Example 2: The isprintable() method will return True if the string contains ASCII characters[^2^][2]
mystr = '12345'
print(mystr.isprintable())
# Prints True
mystr = '#1 Harbour Side'
print(mystr.isprintable())
# Prints True
mystr = '\t' # tab character
print(mystr.isprintable())
# Prints False
If you have any questions about this code, you can drop a line in comment.
Comments
Post a Comment