Summary
What is a bytes object? It's a built-in data type. It's similar to a string, but with a different name. It can be used to create a new data type, such as a new type of string. It is a type of data, not a type.
ASCII is one of the encodings used to translate characters into numbers. Each element in a bytes object represents an integer between 0 and 255. The first 128 Unicode characters match the ASCII characters. But there are only 128 more numbers left in a single byte (128-255)
The accented letter é is represented by two bytes. The value of the first of these bytes is c3 in hexadecimal, which is 195 in decimal. The last two bytes combined represent the last character, é. But what do the integers 195 and 169 represent?
There are six bytes in greeting_bytes, even though there are only two characters in the string. You can distinguish each byte as they start with \x to indicate they're escape sequences representing hexadecimal numbers. The first character is represented by the first three bytes out of the six.
Hexadecimal is base 16, which means there are 16 digits instead of 10. Two digits in hexadecimo represent 256 numbers (from 00 to FF, which is 0 to 255 in decimal) Binary follows the same pattern as decimal and hexadeCimal but is in base 2.
Thank you to all those who supported me with a one-off donation recently. This means a lot and helps me focus on writing more articles. The Python Coding Book is available (Ebook and paperback) The NumPy Mindset is available as an Early Release.