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