In this tutorial, we will learn about the Python bytearray[] method with the help of examples.
The bytearray[]
method returns a bytearray object which is an array of the given bytes.
Example
prime_numbers = [2, 3, 5, 7]
# convert list to bytearray
byte_array = bytearray[prime_numbers]
print[byte_array]
# Output: bytearray[b'\x02\x03\x05\x07']
bytearray[] Syntax
The syntax of bytearray[]
method is:
bytearray[[source[, encoding[, errors]]]]
bytearray[]
method returns a bytearray object [i.e. array of bytes] which is mutable
[can be modified] sequence of integers in the range 0