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 Find Numbers Divisible by Another Number
Python Program to Check Armstrong Number
Check If a String Is Numeric in Java
Python classmethod()
Python Tuple
Python List sort()
Python Decorators
Python Program to Get File Creation and Modification Date
Python Program to Find the Largest Among Three Numbers
Python Multiple Inheritance
Python Program to Differentiate Between del, remove, and pop on a List
Python Inheritance
Python Program to Display Powers of 2 Using Anonymous Function
Python getattr()
Python Program to Count the Number of Digits Present In a Number
Python time Module
Python Program to Check the File Size
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python String lower()
Python Program to Check if a Number is Odd or Even
Python setattr()
Python Operator Overloading
Python Set symmetric_difference_update()
Python String lstrip()
Python Dictionary clear()
Array to String Conversions
Python Set intersection()
Python Program to Check Whether a String is Palindrome or Not
Python Program to Create a Countdown Timer
Python String capitalize()
Count Occurrences of a Char in a String
Python Type Conversion and Type Casting