Python Glossary Русский

all Python 3Byte sequencesfunction

bytearray.isalpha

bytearray — is* checks

All bytes are ASCII letters and non-empty.

Syntax

ba.isalpha(...)

Unlike str.isalpha(), there is no Unicode here: only ASCII A-Z and a-z count as letters. A word encoded in UTF-8 from any non-Latin alphabet returns False, since its bytes sit above 127. If the task is about text rather than raw bytes, decode to a string first and test that.

Examples

print(bytearray(b'abc').isalpha())   # → True
print(bytearray(b'abc1').isalpha())   # → False
print(bytearray(b'Hello World').isalpha())   # → False
print(bytearray(b'').isalpha())   # → False
print(bytearray(b'abc1').isalnum())   # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy