all Python 3Byte sequencesfunction
bytearray.isdigit
bytearray — is* checks
All bytes are ASCII digits and non-empty.
Syntax
ba.isdigit(...)
It answers exactly one question: are all bytes digits 0-9. A minus sign, decimal point, space or thousands separator makes it False, so it is not an "is this a number" test. Bytes have no isdecimal() or isnumeric() counterparts the way str does — attempting the conversion and catching ValueError is the more reliable route.
Examples
print(bytearray(b'123').isdigit()) # → True
print(bytearray(b'12.3').isdigit()) # → False
print(bytearray(b'-5').isdigit()) # → False
print(bytearray(b'').isdigit()) # → False
raw = bytearray(b'2026')
print(int(raw) if raw.isdigit() else None) # → 2026
See also
Open in the full glossarydocs.python.orgReport an inaccuracy