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:
True
if the string is empty or all characters in the string are printableFalse
if 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 bytearray()
Python Operators
Python Namespace and Scope
Python for Loop
Converting a Stack Trace to a String in Java
Java Program to Permute All Letters of an Input String
Python Sets
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Program to Sort Words in Alphabetic Order
Python open()
Python List
Python Program to Delete an Element From a Dictionary
Python Program to Check if a Number is Positive, Negative or 0
Python Program to Find the Size (Resolution) of a Image
Python Program to Print Colored Text to the Terminal
Python frozenset()
Python List clear()
Python Program to Append to a File
Python bool()
Python Program to Copy a File
Python String isnumeric()
Array to String Conversions
JavaScript Methods of RegExp and String
Python String isalnum()
Generate a String
Python Machine Learning - Sebastian Raschka
Python Program to Convert Decimal to Binary Using Recursion
Python type()
Python Program to Measure the Elapsed Time in Python
Java – Reader to String
Python datetime
Python Program to Find Armstrong Number in an Interval