This Python program receives a list of integers and converts it into a byte array using the bytearray() constructor.
Byte arrays are useful for binary data storage, low-level processing, and efficient memory usage.
# Sample list of integers (values must be between 0 and 255)
numbers = [65, 66, 67, 68]
# Convert the list to a byte array
byte_arr = bytearray(numbers)
# Display the result
print("Byte array:", byte_arr)
Byte array: bytearray(b'ABCD')
- The list numbers contains integer values within the valid byte range (0–255)
- The bytearray() function converts the list into a byte array
- If the values correspond to ASCII codes, the output will be readable as characters
- The result is printed using print()