• Python函数-bytearray()


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

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

    参数source:

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

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

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

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

    实例:

     1 >>> a = bytearray(3)
     2 >>> a
     3 bytearray(b'x00x00x00')
     4 >>> a[0]
     5   
     6 >>> a[1]
     7   
     8 >>> a[2]
     9   
    10 >>> b = bytearray("abc")
    11 >>> b
    12 bytearray(b'abc')
    13 >>> b[0]
    14    
    15 >>> b[1]
    16   
    17 >>> b[2]
    18   
    19 >>> c = bytearray([1, 2, 3])
    20 >>> c
    21 bytearray(b'x01x02x03')
    22 >>> c[0]
    23   
    24 >>> c[1]
    25   
    26 >>> c[2]
    27   
    28 >>> d = bytearray(buffer("abc"))
    29 >>> d
    30 bytearray(b'abc')
    31 >>> d[0]
    32   
    33 >>> d[1]
    34   
    35 >>> d[2]
  • 相关阅读:
    Swift 懒加载
    Swift 模型属性
    Swift 循环引用
    Two Sum
    Best Time to Buy and Sell Stock II
    Best Time to Buy and Sell Stock I
    Pascal's Triangle II
    杨辉三角(数组)
    Merge Sorted Array 合并数组
    Plus One
  • 原文地址:https://www.cnblogs.com/guyuyuan/p/6896714.html
Copyright © 2020-2023  润新知