一、 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')
```
- Python 环境
- Python 安装
- IDE
- 包安装
- Anaconda
- WinPython
- eclipse
- eclipse安装
- pydev安装
- 常用英汉
- emmet
- base
- list
- 包 模块 导入
- 查看版本
- dir()
- type 数据类型
- if
- while for
- 迭代器和生成器
- + 和 +=
- numpy
- 体质指数
- 版本
- np数组属性
- 子集
- 数据创建
- 基本操作
- plot
- 中文显示问题
- 随机数
- ::的用法
- asammdf
- 获取所有信号
- 导出csv
- pygraph
- pandas
- 数据结构
- pandans十分钟入门
- io
- 爬小说
- struct
- mdf
- ascii
- bytes & bytearray
- 任务
- aardio读取二进制文件原样输出
- 读取数字
- mdf 数据转换
- charles

