all Python 3stringterm
string.printable
special characters
The string of every printable character: digits + ascii_letters + punctuation + whitespace. It is 100 characters long.
Syntax
string.printable # digits + letters + punctuation + whitespace
The name oversells it: newline, carriage return, tab and form feed are all in there, so a "keep only printable characters" filter built on this constant will not strip line breaks. It is also ASCII-only, so Cyrillic or accented letters fall out of it, whereas str.isprintable() judges by Unicode and calls 'я' printable but a newline not.
Examples
import string
print(len(string.printable)) # → 100
print(string.printable[:10]) # → 0123456789
non_printable = [c for c in 'hello\x00world' if c not in string.printable] # → ['\x00']
print('A' in string.printable) # → True
print('\x01' in string.printable) # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy