英文文档
class bytearray([source[, encoding[, errors]]])
Return a new array of bytes. The bytearray class is a mutable sequence of integers in the range 0 <= x < 256. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the bytes type has, see Bytes and Bytearray Operations.
bytearray()
1、返回值为一个新的字节数组
2、当3个参数都不传的时候,返回长度为0的字节数组
>>> b = bytearray()
>>> b
bytearray(b'')
>>> len(b)
0
3、当source参数为字符串时,encoding参数也必须提供,函数将字符串使用str.encode方法转换成字节数组
>>> bytearray('中文字符')
Traceback (most recent call last):
File "<pyshell#54>", line 1, in <module>
bytearray('中文字符')
TypeError: string argument without