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:
Deep Learning with Python - Francois Cholletf
Python Statement, Indentation and Comments
Python Program to Check if a Number is Odd or Even
Python sorted()
Python String rstrip()
Python String split()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python String isalnum()
Python Program to Count the Number of Each Vowel
Python Program to Multiply Two Matrices
Python abs()
Python staticmethod()
Python String expandtabs()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python set()
Check If a String Is Numeric in Java
Python Program to Make a Flattened List from Nested List
Python List append()
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Program to Extract Extension From the File Name
Python String count()
Why String is Immutable in Java?
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Dictionary items()
Python Program to Calculate the Area of a Triangle
Python repr()
Python globals()
Python Dictionary
Python Program to Add Two Numbers
Python Program to Delete an Element From a Dictionary
Python String casefold()
Java – Reader to String