Bytes Methods

bytes.isascii()

Check whether every byte lies between 0 and 127 inclusive; empty data also passes. Control bytes such as NUL and DEL qualify. This does not establish printability, token validity or the intended text encoding. Introduced in Python 3.7. The receiver is not modified. Returns a Boolean, not a transformed sequence. These operations are intended for ASCII-compatible data, not arbitrary binary formats.

Formal Syntax & Structure

python syntaxpython
data.isascii()

Return Value

bool

True when the stated condition holds; False otherwise.

Working Example

Example Snippetpython
for token in (bytes(b'API\x00'), bytes(b'\x7f'), bytes(b'\x80')):    print(token, token.isascii())
Python Reference