Table of Contents
The isprintable() methods returns True if all characters in the string are printable or the string is empty. If not, it returns False.
Characters that occupy printing space on the screen are known as printable characters. For example:
- letters and symbols
- digits
- punctuation
- whitespace
The syntax of isprintable() is:
string.isprintable()
1. isprintable() Parameters
isprintable() doesn’t take any parameters.
2. Return Value from isprintable()
The isprintable() method returns:
Trueif the string is empty or all characters in the string are printableFalseif the string contains at least one non-printable character
3. Example 1: Working of isprintable()
s = 'Space is a printable'
print(s)
print(s.isprintable())
s = '\nNew Line is printable'
print(s)
print(s.isprintable())
s = ''
print('\nEmpty string printable?', s.isprintable())
Output
Space is a printable True New Line is printable False Empty string printable? True
4. Example 2: How to use isprintable()?
# written using ASCII
# chr(27) is escape character
# char(97) is letter 'a'
s = chr(27) + chr(97)
if s.isprintable() == True:
print('Printable')
else:
print('Not Printable')
s = '2+2 = 4'
if s.isprintable() == True:
print('Printable')
else:
print('Not Printable')
Output
Not Printable Printable
Related posts:
Python List index()
Array to String Conversions
Deep Learning with Python - Francois Chollet
Python String isalpha()
Python String strip()
Python setattr()
Python Iterators
Python Package
Python Global, Local and Nonlocal variables
Python Program to Count the Number of Occurrence of a Character in String
Java Program to Permute All Letters of an Input String
Python @property decorator
Convert Character Array to String in Java
Python List pop()
Python zip()
Python Program to Reverse a Number
Python String isidentifier()
Python Program to Get Line Count of a File
Python Program to Measure the Elapsed Time in Python
Python __import__()
Python Program to Differentiate Between del, remove, and pop on a List
Python List insert()
Python Set remove()
Python Program to Get the File Name From the File Path
Python Program to Find Factorial of Number Using Recursion
Python Dictionary copy()
Python type()
Python Program to Convert Two Lists Into a Dictionary
Python datetime
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Dictionary values()
Python bool()