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:
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Java – Generate Random String
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Deep Learning Cookbook - Indra den Bakker
Python Program to Check Whether a String is Palindrome or Not
Converting a Stack Trace to a String in Java
Python id()
Python open()
Machine Learning with Python for everyone - Mark E.Fenner
Python String format()
Python Program to Compute the Power of a Number
Python Program to Find LCM
Python List insert()
Python abs()
Python String swapcase()
Python dir()
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Check Prime Number
Python min()
Python Program to Find Factorial of Number Using Recursion
Python Set issuperset()
Python Program to Reverse a Number
Deep Learning with Applications Using Python - Navin Kumar Manaswi
CharSequence vs. String in Java
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Program to Convert Kilometers to Miles
Jackson – Marshall String to JsonNode
Python String count()
Python List
Python String isupper()
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili