The \xhh indicates a hex value of hh. i.e. it is the Python 3 way of encoding 0xhh.

See https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals

The b at the start of the string is an indication that the variables should be of bytes type rather than str. The above link also covers that. The \n is a newline character.

You can use bytearray to store and access the data. Here's an example using the byte string in your question.

example_bytes = b'\x8a\n\x1e+\x1f\x84V\xf2\xca$\xb1'
encoded_array = bytearray(example_bytes)
print(encoded_array)
>>> bytearray(b'\x8a\n\x1e+\x1f\x84V\xf2\xca$\xb1')
# Print the value of \x8a which is 138 in decimal.
print(encoded_array[0])
>>> 138
# Encode value as Hex.
print(hex(encoded_array[0]))
>>> 0x8a

Hope this helps.

Answer from Andrew McDowell on Stack Overflow
🌐
Programiz
programiz.com › python-programming › methods › built-in › bytes
Python bytes()
Online Python Online JavaScript Online SQL Online Java Online HTML Online C Online C++ Online C# Online PHP Online Swift Online Kotlin Online TypeScript Online Go Online Rust Online Scala Online Dart Online R Online Ruby ... The bytes() method returns an immutable bytes object initialized with ...
Discussions

Bytes representation in Python - Stack Overflow
I need to do some work with bytes in Python and I've come across a byte string I don't really understand: b"H\x00\x84\xffQ\x00\xa6\xff+\x00\x96\xff\xc2\xffI\xff\xa5\xff'\xff\x8a\xff\x19\xff\x1... More on stackoverflow.com
🌐 stackoverflow.com
Variables & Data Types
Feels like you're confusing r/Python with your personal blog, tbh... The size of the box you assign is referred to as data type Floating-point numbers are normally 4 or 8 bytes long. Say, I have an array of bytes like char a[4] = {4, 78, 3, 9};, which is also 4 bytes long. Obviously, it doesn't mean that a is a floating-point number, right? A type is more or less a collection of values one can perform a certain set of operations on. Like, you can do addition, subtraction, multiplication and division on integers and floats. You can also perform addition on lists, but you cannot divide them because "it doesn't make sense". Also, classes in general are characterized by the methods they define, a.k.a. by the operations that can be performed on a class, not by its width. More on reddit.com
🌐 r/Python
5
2
October 19, 2019
[Python 3] Understanding the difference between byte string and strings.
The bytes that python is using under the covers aren't necessarily the bytes that you want. If I want to put the word café on my website then I probably need the bytes 0x63 0x61 0x66 0xc3 0xa9. But the bytes that python currently uses to represent the string 'café' under the covers is actually 0x63 0x61 0x66 0xe9. I can't use the same bytes that python uses because python doesn't use the bytes I need. Python chooses to represent things using a certain pattern of bytes for it's own reasons, but there are many different ways to express the same thing using bytes. You may wish to (or be forced to) use a different one than what python picks. bytes objects allow you to do that. By not having your code rely on the way that python represents things in bytes, it makes it possible for python to change the representation if it finds a better way. Dictionaries were recently updated to make them significantly smaller, but in order to do this python had to change the byte representation of dictionaries. They would have broken other code that relied on that representation. More on reddit.com
🌐 r/learnpython
8
7
October 20, 2018
Can someone explain how the datatype beginning with "\x" work?
That's not a "datatype", it's just a way of denoting unprintable characters in strings. "\x00" is the character with the hex code "00". "\xFF" is the character with the hex code "FF", or 255 in decimal. More on reddit.com
🌐 r/learnpython
5
6
June 29, 2017
🌐
Real Python
realpython.com › python-bytes
Bytes Objects: Handling Binary Data in Python – Real Python
March 5, 2025 - You convert a Python string to bytes using the str.encode() method, the bytes() function, or the codecs module. Endianness refers to the byte order used to represent binary data in memory, which can be either little-endian or big-endian.
🌐
Python Morsels
pythonmorsels.com › representing-binary-data-with-bytes
Representing binary data with bytes - Python Morsels
December 27, 2021 - If we loop over a string in Python, we'll get back sub-strings representing each of the characters in that string: >>> text = "hello" >>> list(text) ['h', 'e', 'l', 'l', 'o'] What do you think we'll get if we loop over a bytes object? ... Since bytes objects represent binary data, when we loop over them we get back numbers (from 0 to 255) representing each of the bytes in that binary data:
🌐
w3resource
w3resource.com › python › python-bytes.php
Python Bytes, Bytearray
>>> # bytes objects are immutable sequences of integers, each value in the sequence >>> # string objects are immutable sequences of unicode characters. >>> x = "Python String" >>> y = b"Python String" >>> print(x) Python String >>> print(y) b'Python String' >>> # Found in unicode representation of characters but not in ascii >>> x = "Python" >>> y = bytes("Python", "utf8") >>> print(x) Python >>> print(y) b'Python' >>>
🌐
The Python Coding Stack
thepythoncodingstack.com › the python coding stack › `bytes`: the lesser-known python built-in sequence • and understanding utf-8 encoding
`bytes`: The Lesser-Known Python Built-In Sequence • And Understanding UTF-8 Encoding
July 15, 2025 - The last two bytes combined represent the last character, é. ... Do you want to try video courses designed and delivered in the same style as these posts? You can get a free trial at The Python Coding Place and you also get access to a members-only forum.
🌐
Mimo
mimo.org › glossary › python › bytes
Mimo: The coding platform you need to learn Web Development, Python, and more.
For lower-level conversions, built-in ... provides the bytearray type. This lets you modify the binary content directly: ... Each element represents a single byte, so it must be between 0 and 255....
Find elsewhere
🌐
iO Flood
ioflood.com › blog › python-bytes
Python Bytes Data Type | bytes() Function Guide
February 6, 2024 - Python bytes are a sequence of integers in the range of 0-255. You can create bytes in Python using the bytes() function or a bytes literal. ... In this example, we’re creating a bytes object in Python using the bytes() function.
🌐
GeeksforGeeks
geeksforgeeks.org › python-bytes-method
Python bytes() method - GeeksforGeeks
January 2, 2025 - If the string contains characters ... to bytes using the bytes() function, for this we take a variable with string and pass it into the bytes() function with UTF-8 parameters....
🌐
W3Schools
w3schools.com › python › ref_func_bytes.asp
Python bytes() Function
The bytes() function returns a bytes object. It can convert objects into bytes objects, or create empty bytes object of the specified size. The difference between bytes() and bytearray() is that bytes() returns an object that cannot be modified, ...
🌐
Coventry University
github.coventry.ac.uk › pages › CUEH › py-quickstart › data
Representation of Data - Python for Hackers - Quick Start
To transform a number into an octal in python, all we need to do is use the oct() function on it. Base 16, hexadecimal, or generally referred to as 'hex', is another way to compress a binary number. As bytes are 8 bits or binary digits long, it's quite unruly to have to deal with with them in code or on paper, and it's much easier to make a mistake when you have large numbers of them. Splitting 8 bits into two separate 4 bit numbers and representing them with a single symbol is a great way to solve that though, and exactly what we do in base 16.
🌐
Real Python
realpython.com › ref › builtin-types › bytes
bytes | Python’s Built-in Data Types – Real Python
The built-in bytes data type allows you to represent and manipulate immutable sequences of bytes, which are numbers in the range 0 <= x < 256.
🌐
Python
docs.python.org › 3.1 › library › stdtypes.html
5. Built-in Types — Python v3.1.5 documentation
September 6, 2021 - To construct byte arrays, use the bytearray() function. ... While string objects are sequences of characters (represented by strings of length 1), bytes and bytearray objects are sequences of integers (between 0 and 255), representing the ASCII value of single bytes.
🌐
CodeRivers
coderivers.org › blog › bytes-object-python
Mastering the `bytes` Object in Python - CodeRivers
February 22, 2026 - A bytes object is represented as a sequence of bytes enclosed in single or double quotes, preceded by the b prefix. For example: ... In the above example, b_data is a bytes object. The characters inside the quotes are interpreted as bytes, not as Unicode characters as in regular strings.
🌐
Wikiversity
en.wikiversity.org › wiki › Python_Concepts › Bytes_objects_and_Bytearrays
Python Concepts/Bytes objects and Bytearrays - Wikiversity
January 22, 2025 - One byte is a memory location with a size of 8 bits. A bytes object is an immutable sequence of bytes, conceptually similar to a string · Because each byte must fit into 8 bits, each member x of a bytes object is an unsigned int that satisfies 0≤x≤0b1111_1111
🌐
Python
docs.python.org › 3 › c-api › bytes.html
Bytes Objects — Python 3.14.7 documentation
If the reallocation fails, the original bytes object at *bytes is deallocated, *bytes is set to NULL, MemoryError is set, and -1 is returned. PyObject *PyBytes_Repr(PyObject *bytes, int smartquotes)¶ · Part of the Stable ABI. Thread safety: Atomic. Get the string representation of bytes.
🌐
CodeRivers
coderivers.org › blog › bytes-in-python
Understanding Bytes in Python: A Comprehensive Guide - CodeRivers
February 22, 2026 - To convert a string to a bytes object, you need to specify an encoding. Common encodings include 'utf-8', 'ascii', 'gbk', etc. string = "Python is great" byte_obj = string.encode('utf-8') print(byte_obj)
🌐
DataCamp
datacamp.com › tutorial › string-to-bytes-conversion
How to Convert String to Bytes in Python | DataCamp
June 5, 2024 - In Python, use the .encode() method on a string to convert it into bytes, optionally specifying the desired encoding (UTF-8 by default). ... Strings represent human-readable text and are one of the most basic and important data types in computer programming. However, each character in a text ...