all Python 3Byte sequencesfunction
bytearray.isalnum
bytearray — is* checks
All bytes are ASCII letters/digits and non-empty.
Syntax
ba.isalnum(...)
The check is strictly ASCII: only A-Z, a-z count as letters and only 0-9 as digits, so any byte at 128 or above (Cyrillic in UTF-8, for instance) makes it False. Underscore, hyphen, dot and space fail too, so this is not a usable "safe filename or identifier" test — for that, spell out your own allowed set.
Examples
print(bytearray(b'abc123').isalnum()) # → True
print(bytearray(b'abc 123').isalnum()) # → False
print(bytearray(b'user_42').isalnum()) # → False
print(bytearray(b'').isalnum()) # → False
print(bytearray('привет'.encode()).isalnum()) # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy