In this lesson, you’ll explore the common sequence operations that bytes
objects support. You’ll take a closer look at:
- The
in
andnot in
operators - Concatenation (
+
) and replication (*
) operators - Indexing and slicing
- Built-in functions
len()
,min()
, andmax()
- Methods for
bytes
objects bytes.fromhex(<s>)
andb.hex()
For more information about hexadecimal values, check out the following resources:
Here’s how to use the in
and not in
operators:
Alain Rouleau on July 29, 2020
That
bytes.fromhex(' aa 68 32 af ')
was quite the head-scratcher! And as to why the output has both an'h'
and a'2'
inb'\xaah2\xaf'
? You know, there’s no'h'
in hexadecimal and why'2'
?But what appears to be happening is that hexadecimal 68 equals decimal 104 which in turn is ascii for
'h'
. Plus hexidecimal 32 is decimal 50 which in turn is ascii for'2'
. All pretty crazy!