Returns a new array object that cannot be modified by an array element. Range of values per element : 0 <= x <max. the main difference between the bytes function and the ByteArray function is that the elements of the object produced by the bytes function cannot be modified, and the elements of an object produced by the ByteArray function can be modified. Therefore, except for modifiable object functions that are not the same as the ByteArray function, all other usage methods are the same. Finally, its parameters are defined in the same way as the ByteArray function.
Example:
#bytes () function A = bytes (' abc ', ' Utf-8 ') print (a) b = bytes (1) print (b) c = bytes ([2,3,6,8]) print (c)
The output results are as follows:
B ' ABC '
B ' \x00 '
B ' \x02\x03\x06\x08 '
Python standard library: Built-in function bytes ([source[, encoding[, errors]])