English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
If all characters in the string are printable or the string is empty, the isprintable() method will return True. Otherwise, it will return False.
Characters that occupy screen printing space are called printable characters. For example:
Letters and symbols
Numbers
Punctuation
Space
The syntax of isprintable() is:
string.isprintable()
isprintable() method has no parameters.
isprintable() method returns:
True if the string is empty or all characters in the string are printable
False if the string contains at least one non-Printable() characters
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())
The output when running the program is:
Space is a printable True New Line is printable False Empty string printable? True
# Use ASCII to write # char(27) is an escape character # char(97) is letter 'a' s = chr(27) + chr(97) if s.isprintable() == True: print('Printable') else: print('Non-printable') s = '2+2 = 4' if s.isprintable() == True: print('Printable') else: print('Non-printable')
The output when running the program is:
Non-printable Printable