In Python, isprintable () — it is a built-in method used to process strings.
The isprintable () methods return True if all characters in the string are printable or if the string is empty. Otherwise, "False" is returned.
This function is used to check if the argument contains any printable characters, such as:
string.isprintable () strong> Parameters: isprintable () does not take any parameters Returns: 1.True- If all characters in the string are printable or the string is empty. 2.False- If the string contains 1 or more non printable characters.
Input: string = 'My name is Ayush' Output: True Input: string =' My name is Ayush' Output: False Input: string = '' Output: True
True False True
Errors or exceptions strong>
1. The function takes no arguments, so no parameters must be passed, otherwise it returns an error.
2. The only space that can be printed is space or "", otherwise every space character cannot be printed and the function returns "False".
3. An empty string is considered printable and returns "True".
Usage: For a given string in python, count the number of non-printable characters in the string and replace the non-printable characters with a space.
Input: string = 'My name is Ayush' Output: 0 My name is Ayush Input: string =' My name is Ayush' Output: 3 My name is Ayush
1. Initialize an empty newline and the variable count = 0.
2. Go through the given string character by character to its length, check if the character is unprintable character.
3. If it is a non-printable character, increment the counter by 1 and add a space on the new line.
4. Otherwise, if it is a printable character, add it on a new line as it is.
5. Print the counter value and a new line.
3 Python.Engineering name is CS portal