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:
1 | 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()
1 2 3 4 5 6 7 8 9 10 | 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
1 2 3 4 5 6 7 | Space is a printable True New Line is printable False Empty string printable? True |
4. Example 2: How to use isprintable()?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # 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
1 2 | Not Printable Printable |
Related posts:
Python String ljust()
Python strptime()
Python Iterators
Python Keywords and Identifiers
Python String format()
Python String endswith()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Set update()
Python Program to Create a Countdown Timer
Python Program to Print all Prime Numbers in an Interval
Python dict()
Python String count()
Python Program to Get the Full Path of the Current Working Directory
Python Closures
Python Program to Shuffle Deck of Cards
Python frozenset()
Python Set difference_update()
Python max()
Python String isnumeric()
Python String isidentifier()
Python exec()
Python Program to Access Index of a List Using for Loop
Python filter()
Python Strings
Python String expandtabs()
Python Program to Count the Occurrence of an Item in a List
Python sleep()
Python Set remove()
Python @property decorator
Python object()
Python Program to Solve Quadratic Equation
Convert String to int or Integer in Java