In your special case, it is enough to just check
if bytes == 'ELF':
to test all three bytes in one step to be the three characters E
, L
and F
.
But also if you want to check the numerical values, you do not need to unpack anything here. Just use ord(bytes[i])
(with i in 0, 1, 2) to get the byte values of the three bytes.
Alternatively you can use
byte_values = struct.unpack('bbb', bytes)
to get a tuple of the three bytes. You can also unpack that tuple on the fly in case the bytes have nameable semantics like this:
width, height, depth = struct.unpack('bbb', bytes)
Use 'BBB'
instead of 'bbb'
in case your byte values shall be unsigned.