bytearray函数

 bytearray:

  类,可变字节数组

b = bytearray("abc", encoding="utf-8", errors="strict")

# bytearray是字节数组序列
for c, i in enumerate(b):
    print(c,i)


print(b,b[0])  # 该类形式为 bytearray(b'abc')

b[0] = 100  # byearray可变
print(b,b[0])


# bytearray范围在[0, 256)
try:
    b[0] = 260
except:
    print("out of range (0,256)")
原文地址:https://www.cnblogs.com/ShuComputerProgram/p/10340572.html