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:
Converting a List to String in Java
Java String Conversions
Python String partition()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python globals()
Python String isalnum()
Python Program to Remove Punctuations From a String
Python Program to Find the Square Root
APIs in Node.js vs Python - A Comparison
Python strptime()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python time Module
Python Set symmetric_difference()
Python Program to Find HCF or GCD
Python Program to Check if a Key is Already Present in a Dictionary
Deep Learning in Python - LazyProgrammer
Python Get Current time
Python Program to Trim Whitespace From a String
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python String title()
Python List Comprehension
Python Program to Convert Two Lists Into a Dictionary
Python Anonymous / Lambda Function
Python Function Arguments
Python List pop()
Python Program to Transpose a Matrix
Python print()
Python setattr()
Python property()
Python String rjust()
Python Program to Convert String to Datetime
Python Variables, Constants and Literals