Python String isprintable() Method Last Updated : 12 Aug, 2021 Comments Improve Suggest changes Like Article Like Report Python String isprintable() is a built-in method used for string handling. The isprintable() method returns "True" if all characters in the string are printable or the string is empty, Otherwise, It returns "False". This function is used to check if the argument contains any printable characters such as: Digits ( 0123456789 )Uppercase letters ( ABCDEFGHIJKLMNOPQRSTUVWXYZ )Lowercase letters ( abcdefghijklmnopqrstuvwxyz )Punctuation characters ( !”#$%&'()*+, -./:;?@[\]^_`{ | }~ )Space ( ) Syntax: string.isprintable() Parameters: isprintable() does not take any parameters Returns: True - If all characters in the string are printable or the string is empty.False - If the string contains 1 or more nonprintable characters. Errors Or Exceptions: The function does not take any arguments, therefore no parameters should be passed, otherwise, it returns an error.The only whitespace character which is printable is space or " ", otherwise every whitespace character is non-printable and the function returns "False".The empty string is considered printable and it returns "True".Example 1Input : string = 'My name is Ayush' Output : True Input : string = 'My name is \n Ayush' Output : False Input : string = '' Output : True Python3 # Python code for implementation of isprintable() # checking for printable characters string = 'My name is Ayush' print(string.isprintable()) # checking if \n is a printable character string = 'My name is \n Ayush' print(string.isprintable()) # checking if space is a printable character string = '' print( string.isprintable()) Output: True False TrueExample 2: Practical Application Given a string in python, count the number of non-printable characters in the string and replace non-printable characters with a space. Input : string = 'My name is Ayush' Output : 0 My name is Ayush Input : string = 'My\nname\nis\nAyush' Output : 3 My name is Ayush Algorithm: Initialize an empty new string and a variable count = 0. Traverse the given string character by character up to its length, check if the character is a non-printable character. If it is a non-printable character, increment the counter by 1, and add a space to the new string. Else if it is a printable character, add it to the new string as it is.Print the value of the counter and the new string. Python3 # Python implementation to count # non-printable characters in a string # Given string and new string string ='GeeksforGeeks\nname\nis\nCS portal' newstring = '' # Initialising the counter to 0 count = 0 # Iterating the string and # checking for non-printable characters # Incrementing the counter if a # non-printable character is found # and replacing it by space in the newstring # Finally printing the count and newstring for a in string: if (a.isprintable()) == False: count+= 1 newstring+=' ' else: newstring+= a print(count) print(newstring) Output: 3 GeeksforGeeks name is CS portal Comment More infoAdvertise with us Next Article Python String isprintable() Method A AyushSaxena Follow Improve Article Tags : Misc Python Python-Built-in-functions Practice Tags : Miscpython Similar Reads Python String endswith() Method The endswith() method is a tool in Python for checking if a string ends with a particular substring. It can handle simple checks, multiple possible endings and specific ranges within the string. This method helps us make our code cleaner and more efficient, whether we're checking for file extensions 2 min read expandtabs() method in Python expandtabs() method in Python is used to replace all tab characters (\t) in a string with spaces. This method allows for customizable spacing, as we can specify the number of spaces for each tab. It is especially useful when formatting text for better readability or alignment. Let's understand with 3 min read Python String find() Method find() method in Python returns the index of the first occurrence of a substring within a given string. If the substring is not found, it returns -1. This method is case-sensitive, which means "abc" is treated differently from "ABC". Example:Pythons = "Welcome to GeekforGeeks!" index = s.find("Geekf 2 min read Python String format() Method format() method in Python is a tool used to create formatted strings. By embedding variables or values into placeholders within a template string, we can construct dynamic, well-organized output. It replaces the outdated % formatting method, making string interpolation more readable and efficient. E 8 min read Python String format_map() Method Python String format_map() method is an inbuilt function in Python, which is used to return a dictionary key's value. Syntax: string.format_map(z) Parameters: Here z is a variable in which the input dictionary is stored and string is the key of the input dictionary. input_dict: Takes a single parame 2 min read Python String index() Method The index() method in Python is used to find the position of a specified substring within a given string. It is similar to the find() method but raises a ValueError if the substring is not found, while find() returns -1. This can be helpful when we want to ensure that the substring exists in the str 2 min read Python String isalnum() Method The isalnum() method is a string function in Python that checks if all characters in the given string are alphanumeric. If every character is either a letter or a number, isalnum() returns True. Otherwise, it returns False. For Example:Pythons = "Python123" res = s.isalnum() print(res)OutputTrue Exp 2 min read Python String isalpha() Method The isalpha() method checks if all characters in a given string are alphabetic. It returns True if every character in the string is a letter and False if the string contains any numbers, spaces, or special characters.Letâs start with a simple example of using isalpha()Pythons1 = "HelloWorld" res1 = 2 min read Python string isdecimal() Method In Python, the isdecimal() method is a quick and easy way to check if a string contains only decimal digits. It works by returning True when the string consists of digits from 0 to 9 and False otherwise. This method is especially useful when we want to ensure that user inputs or string data are stri 3 min read Python String isdigit() Method The isdigit() method is a built-in Python function that checks if all characters in a string are digits. This method returns True if each character in the string is a numeric digit (0-9) and False otherwise. Example:Pythona = "12345" print(a.isdigit()) b = "1234a5" print(b.isdigit())OutputTrue False 3 min read Like