小白教程
所有教程
关于
Search
172.70.131.102
172.70.131.102
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python func bytearray”的源代码
本页内容
上一节:
Python_func_sum
下一节:
Python3_func_filter
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:bytearray()}}[[Category:python3 built in functions|30]] = Python bytearray() 函数 = [[python built in functions|Python 内置函数]] == 描述 == '''bytearray()''' 方法返回一个新字节数组。这个数组里的元素是可变的,并且每个元素的值范围: 0 == 语法 == bytearray()方法语法: <sample title="" desc="" lang="python" hererun="1"> class bytearray([source[, encoding[, errors]]]) </sample> == 参数 == * 如果 source 为整数,则返回一个长度为 source 的初始化数组; * 如果 source 为字符串,则按照指定的 encoding 将字符串转换为字节序列; * 如果 source 为可迭代类型,则元素必须为[0 ,255] 中的整数; * 如果 source 为与 buffer 接口一致的对象,则此对象也可以被用于初始化 bytearray。 * 如果没有输入任何参数,默认就是初始化数组为0个元素。 == 返回值 == 返回新字节数组。 以下实例展示了 bytearray() 的使用方法: <sample title="" desc="" lang="python" hererun="1"> >>>bytearray() bytearray(b'') >>> bytearray([1,2,3]) bytearray(b'\x01\x02\x03') >>> bytearray('xiaobai', 'utf-8') bytearray(b'xiaobai') >>> </sample> [[python built in functions|Python 内置函数]]
返回至“
Python func bytearray
”。
上一节:
Python_func_sum
下一节:
Python3_func_filter