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 Program to Get the Full Path of the Current Working Directory
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Converting String to Stream of chars
Python Functions
Python Program to Differentiate Between type() and isinstance()
Python List insert()
String Processing with Apache Commons Lang 3
Python Set clear()
Python Data Structures and Algorithms - Benjamin Baka
Python all()
Python Program to Split a List Into Evenly Sized Chunks
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python String rsplit()
Python Get Current time
Python String rpartition()
Adding a Newline Character to a String in Java
Python String capitalize()
Python Type Conversion and Type Casting
Python Program to Check if a Key is Already Present in a Dictionary
Python String endswith()
Generate a String
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Global, Local and Nonlocal variables
Python bytearray()
Python Program to Parse a String to a Float or Int
Python Program to Count the Number of Each Vowel
Python Program to Display the multiplication Table
Python String casefold()
Python Program to Count the Number of Digits Present In a Number
Python staticmethod()