Python Glossary Русский

all Python 3stringterm

string.whitespace

special characters

The string of the whitespace characters: space, tab, newline, carriage return, vertical tab and form feed.

Syntax

string.whitespace  # ' \t\n\r\x0b\x0c'

There are exactly six ASCII characters here, while str.strip() and str.split() with no arguments use the wider Unicode notion of whitespace, non-breaking space U+00A0 included. So a string pasted from a web page can pass a "contains nothing from string.whitespace" check and still behave as if the spaces were never removed.

Examples

import string
print(repr(string.whitespace))  # → ' \t\n\r\x0b\x0c'
print(len(string.whitespace))  # → 6
no_ws = ''.join(c for c in 'a b\tc' if c not in string.whitespace)  # → 'abc'
print(' ' in string.whitespace)  # → True
print('\t' in string.whitespace)  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy