Python Glossary Русский

all Python 3Byte sequencesfunction

bytes.isspace

bytes — is* checks

Check that all bytes are whitespace and non-empty.

Syntax

b.isspace(...)

Only ASCII bytes count as whitespace here: space, \t, \n, \r, \x0b and \x0c. Unicode spaces are not included — b'\xa0'.isspace() is False, while the same method on a str non-breaking space returns True. Watch the empty case too: b''.isspace() is False, so "blank or whitespace-only line" is better tested as not line.strip().

Examples

print(b'   '.isspace())   # → True
print(b' \t\n'.isspace())   # → True
print(b'\x0b\x0c\r'.isspace())   # → True
line = b'  \n'
print('пустая' if line.isspace() else 'данные')   # → пустая
print(b''.isspace())   # → False

See also

Open in the full glossarydocs.python.orgReport an inaccuracy