python函数之bytearray用法详解


本文摘自php中文网,作者巴扎黑,侵删。

bytearray([source [, encoding [, errors]]])

中文说明:

bytearray([source [, encoding [, errors]]])返回一个byte数组。Bytearray类型是一个可变的序列,并且序列中的元素的取值范围为 [0 ,255]。

参数source:

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

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

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

如果source为与buffer接口一致的对象,则此对象也可以被用于初始化bytearray.。

版本:在python2.6后新引入,在python3中同样可以使用

英文说明:

Return a new array of bytes. The bytearray type is a mutable sequence of integers in the range 0 <= x < 256. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the str type has, see String Methods.

The optional source parameter can be used to initialize the array in a few different ways:

If it is a string, you must also give the encoding (and optionally, errors) parameters; bytearray() then converts the string to bytes using str.encode().

If it is an integer, the array will have that size and will be initialized with null bytes.

If it is an object conforming to the buffer interface, a read-only buffer of the object will be used to initialize the bytes array.

If it is an iterable, it must be an iterable of integers in the range 0 <= x < 256, which are used as the initial contents of the array.

Without an argument, an array of size 0 is created.

阅读剩余部分

相关阅读 >>

简单易学的Python语言,黑客也喜欢她

Python实现的hmacmd5加密算法示例_Python

基于Python的图片修复程序(实现水印去除)

Python中arange是什么意思

Python解释器安装在哪里

Python实现针对给定字符串寻找最长非重复子串

如何离开/退出/停用Python的virtualenv

Python如何批量修改文件后缀名?批量修改文件后缀名的方法

pycharm和Python区别是什么

在电脑上怎么下载Python

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...