Python Glossary Русский

all Python 3Byte sequencesfunction

bytes.isalnum

bytes — is* checks

Check that all bytes are ASCII letters/digits and non-empty.

Syntax

b.isalnum(...)

The test is strictly ASCII, unlike str.isalnum, which accepts any Unicode letter or digit: a non-Latin word is True as a str and False once encoded to bytes. It is also not a name validator — underscore, hyphen and dot all fail, so it fits 'letters and digits only' but not 'valid filename' or 'valid identifier'.

Examples

print(b'abc123'.isalnum())   # → True
print('42'.encode().isalnum())   # → True
print(b'abc 123'.isalnum())   # → False
print(b'user_42'.isalnum())   # → False
print(b''.isalnum())   # → False

See also

Open in the full glossarydocs.python.orgReport an inaccuracy