Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python Bytes and Bytearray Code

Practice constructing bytes, decoding binary data, mutating bytearray, and reading hexadecimal byte values.

Core ~10 min read

Challenge 1

Create a bytes object from the three integer byte values 72, 73, and 33.

python Your answer
message = 
print(message)

Press Ctrl⌘Enter to check your answer

Challenge 2

Decode the UTF-8 bytes in data into text and store the resulting string in message.

python Your answer
data = b"hello"
message = 
print(message)

Press Ctrl⌘Enter to check your answer

Challenge 3

Change the first byte of buffer from the lowercase letter 'a' to the uppercase letter 'A'.

python Your answer
buffer = bytearray(b"abc")
buffer[0] = 
print(buffer)

Press Ctrl⌘Enter to check your answer

Challenge 4

Create the bytes value represented by the hexadecimal text 46 6f 78 and store it in data.

python Your answer
data = 
print(data)

Press Ctrl⌘Enter to check your answer