💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
一、 bytes 表示字节序列,是一个不可变的数据类型。 ``` class bytearray([source[, encoding[, errors]]]) * 如果 source 为整数,则返回一个长度为 source 的初始化数组; * 如果 source 为字符串,则按照指定的 encoding 将字符串转换为字节序列; * 如果 source 为可迭代类型,则元素必须为\[0 ,255\] 中的整数; * 如果 source 为与 buffer 接口一致的对象,则此对象也可以被用于初始化 bytearray。 * 如果没有输入任何参数,默认就是初始化数组为0个元素。 ``` ``` a = bytes() print('a = {}'.format(a)) #>> a = b'' b = bytes(5) print('b = {}'.format(b)) #>> b = b'\x00\x00\x00\x00\x00' # bytes(iteratable) c = bytes(range(65,90)) print('c = {}'.format(c)) #>> c = b'ABCDEFGHIJKLMNOPQRSTUVWXY' d = bytes('abc',encoding='ascii') print('d = {}'.format(d)) #>> d = b'abc' ``` ``` a = bytearray() print('a = {}'.format(a)) b = bytearray(5) print('b = {}'.format(b)) c = bytearray(range(65,90)) print('c = {}'.format(c)) d = bytearray('abc',encoding='utf8') print('d = {}'.format(d)) 结果: a = bytearray(b'') b = bytearray(b'\x00\x00\x00\x00\x00') c = bytearray(b'ABCDEFGHIJKLMNOPQRSTUVWXY') d = bytearray(b'abc') ```