Behaviour is showed in the code:
>>> b = bytes(b'asdf')
>>> print(type(b))
<class 'bytes'>
>>> print(type(b[0]))
<class 'int'>
Why when I get one byte from the bytes object like this b[0]
, it converts it to int.
Behaviour is showed in the code:
>>> b = bytes(b'asdf')
>>> print(type(b))
<class 'bytes'>
>>> print(type(b[0]))
<class 'int'>
Why when I get one byte from the bytes object like this b[0]
, it converts it to int.
The bytes()
function returns a bytes object. So, b
in your example is an immutable sequence of bytes. Each element of the sequence is unsigned int and accessible via index.