互联网技术 / 互联网资讯 · 2024年1月25日

Python内置函数-bytearray() 函数的云计算开发指南

描述

byteaRRay() 方法返回一个新字节数组。这个数组里的元素是可变的,并且每个元素的值范围: 0 <= x < 256。

语法

以下是 byteaRRay() 方法的语法:

claSS byteaRRay([souRce[, encoding[, Errors]]])

参数

如果 souRce 为整数,则返回一个长度为 souRce 的初始化数组;

如果 souRce 为字符串,则按照指定的 encoding 将字符串转换为字节序列;

如果 souRce 为可迭代类型,则元素必须为[0 ,255] 中的整数;

如果 souRce 为与 buFFeR 接口一致的对象,则此对象也可以被用于初始化 byteaRRay。

如果没有输入任何参数,默认就是初始化数组为0个元素。

返回值

返回新字节数组。

实例

以下实例展示了 byteaRRay() 的使用方法:

云计算开发:Python内置函数-bytearray() 函数详解

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册