What you have are hexadecimal values. So what you're getting is what you should be getting. (Except that you should be getting [2, 0, 48, 3, 53] and not [2, 0, 48, 3, 35].)

If you want the list to have what you have in hexadecimal you can try converting it back to hexadecimal.

testByte = b"\x02\x00\x30\x03\x35"
listTestByte = list(testByte)
print(listTestByte)             # [2, 0, 48, 3, 53]
listTestByteAsHex = [int(hex(x).split('x')[-1]) for x in listTestByte]
print(listTestByteAsHex)        # [2, 0, 30, 3, 35]

Or use string operations, to split at '\x' depending on your purpose.

Answer from sP_ on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-bytes-method
Python bytes() method - GeeksforGeeks
July 11, 2025 - Python ยท s = "Welcome to ... each byte can only hold numbers in that range. When we pass a list of numbers to the bytes() method, Python will create a bytes object where each number in the list corresponds to one ...
Discussions

bytes but print a string!
When printing a bytes type, Python will print the actual characters for ASCII printable characters and \x escapes for non-printable characters. More on reddit.com
๐ŸŒ r/learnpython
3
2
January 15, 2022
python - How to print byte representation of a string? - Stack Overflow
So I have a string like "abcd" and I want to convert it into bytes and print it. I tried print(b'abcd') which prints exactly b'abcd' but I want '\x61\x62\x63\x64'. Is there a single funct... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Printing binary strings
Hello all, Why is the Python 3 interpreter printing byte strings by decoding bytes as UTF-8 (perhaps actually only true for the ASCII analogue codepoints), instead of printing \xNN values? Am I missing something? Thank you More on discuss.python.org
๐ŸŒ discuss.python.org
10
0
April 8, 2025
Python print bytes - Stack Overflow
I'm using a python3 program for binary exploitation, but it's not printing bytes correctly. My program : import struct padding = b" More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
GitHub
gist.github.com โ€บ leveled โ€บ 61ac2196ec4ef7efe0a2a6456c501c39
Print raw bytes to stdout with python ยท GitHub
Print raw bytes to stdout with python. GitHub Gist: instantly share code, notes, and snippets.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ bytes
Python bytes()
Online Python Online JavaScript ... Online Go Online Rust Online Scala Online Dart Online R Online Ruby ... The bytes() method returns an immutable bytes object initialized with the given size and data. ... # convert string to bytes byte_message = bytes(message, 'utf-8') ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ bytes but print a string!
r/learnpython on Reddit: bytes but print a string!
January 15, 2022 -

Im learning crypto ctf with python and there is something that really can't figure out on my own

i have a flag encrypted with XOR with a key. they are represented as hex. after convert it to bytes, i xor them and then use it Crypto.Util.number.long_to_bytes() to find the flag.

before the XOR operation, the bytes values is like "\xa6\xc8\xb6s<\x9b"\xde{\xc0%2f\xa3\x86}\xf5Z\xcd\xe8c^\x19\xc73\x13"

after i removed the key that was XOR with the flag, the bytes values of flag is

crypto{x0r_i5_ass0c1at1v3}

i checked the var with type() and it's a bytes not a str. How come that before that its bytes values has hex values and then only normale characters? Or maybe those arent hex?

๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ 5 best ways to print a python bytearray
5 Best Ways to Print a Python Bytearray - Be on the Right Side of Change
February 24, 2024 - For those needing to manipulate or inspect individual byte values, iterating over the bytearray with a for-loop to print each byte serves well. This method provides a granular view of the dataโ€™s byte values. ... The code iterates over each item in the bytearray, which represents an ASCII value of the characters in the word โ€œpythonโ€, and prints them out one by one on separate lines.
Find elsewhere
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Printing binary strings - Python Help - Discussions on Python.org
April 8, 2025 - Hello all, Why is the Python 3 interpreter printing byte strings by decoding bytes as UTF-8 (perhaps actually only true for the ASCII analogue codepoints), instead of printing \xNN values? Am I missing something? Thโ€ฆ
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-bytes-to-string-how-to-convert-a-bytestring
Python Bytes to String โ€“ How to Convert a Bytestring
April 10, 2023 - In this example, we define a byte string b"Hello, world!" and use the str() constructor to convert it to a string object. We specify the encoding format as utf-8 using the encoding parameter. Finally, we print the resulting string to the console. We can also use the bytes() constructor, a built-in Python function used to create a new bytes object.
๐ŸŒ
w3resource
w3resource.com โ€บ python โ€บ python-bytes.php
Python Bytes, Bytearray
#created from a iterable of ints, string, bytes or buffer objects. x = bytes('Python, bytes', 'utf8') print(x)
๐ŸŒ
Real Python
realpython.com โ€บ python-bytes
Bytes Objects: Handling Binary Data in Python โ€“ Real Python
March 5, 2025 - It can be especially useful when you want to print and align multiple bytes in columns or rows. Because hex is such a widespread notation, Python provides a convenient class method in its bytes data type, which converts a string of hexadecimal digits into a new bytes instance:
๐ŸŒ
Medium
rahulbeniwal26119.medium.com โ€บ bytes-and-string-in-python-6cf5065ef47d
Let's understand What is the difference between bytes and str in Python | Medium
August 2, 2025 - Bytes can only represent unsigned 8 bit character. bstring = b'h\x65llo' print(list(bstring)) print(bstring)
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ bytes-to-string-python
How to Convert Bytes to String in Python | DataCamp
June 12, 2024 - An integer within this range of ... one byte. Let's use the bytes() constructor to create a bytes object from a list: data = bytes([68, 97, 116, 97, 67, 97, 109, 112]) print......
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ python โ€บ print bytes as hex in python
Print bytes as hex in Python - Java2Blog
September 26, 2022 - To print Bytes as Hex in Python, we will loop over a Byte string and get the Hexadecimal representation of each character individually.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-program-to-print-an-array-of-bytes-representing-an-integer
Python program to print an array of bytes representing an integer - GeeksforGeeks
January 24, 2021 - Examples: Input: -14 Output: -1110 Input: -12 Output: -1100 Input: -32 Output: -100000 Let's implement this for the number in different ways : Method 1: Using format specifier 'b' In format spe ...
๐ŸŒ
Theunterminatedstring
theunterminatedstring.com โ€บ python-bits-and-bytes
Python Bits and Bytes - The Unterminated String
May 19, 2018 - Binary values can be stored within the bytes object. This object is immutable and can store raw binary values within the range 0 to 255. Itโ€™s constructor is the aptly named bytes().
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ python โ€บ print bytes without b in python
Print Bytes without b in Python - Java2Blog
September 21, 2022 - The repr() function is similar to the str() constructor in Python. We can use it to get a string representation of different objects. For a byte object, the repr() function invokes the internal bytes.__repr__ magic method. It returns the bytes object as a string and we can manually slice off the prefix b from the same. See the code below. ... This tutorial demonstrated several methods to print bytes without b in Python.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-bytes-to-string-code-examples
Python Bytes to String โ€“ How to Convert a Str to Bytes and Back Again
April 16, 2024 - byte_data = b'Hello' ... string to bytes, and how to convert bytes to a string. You can use the encode() method to convert a string to bytes in Python....
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-convert-strings-to-bytes-in-python
How to convert strings to bytes in Python
We can use the built-in Bytes class in Python to convert a string to bytes: simply pass the string as the first input of the constructor of the Bytes class and then pass the encoding as the second argument.