Search notes:

Python: bytes (type)

The bytes type is a sequence type.
Instances of bytes are represented with the b'…' literal.

Read only type

bytes objects are read-only:
foo = b'Foo'
print(foo[0])  #  70
foo[0] = 102
In contrast bytearray allows to modify individual bytes.

hex()

hex() returns a hexadecimal representation of the bytes object:
>>> b'ABC'.hex()
'414243'
The returned type is str. Compare with binascii.hexlify().

See also

The bytes built-in function
The .encode() method of the string object.
Other Built-in types such as bytes.

Index