UIFlow Guide
bytearray是Python中一个内置的可变序列类型,用于处理字节数据。它类似于bytes类型,但不同之处在于bytearray是可变的,而bytes是不可变的。bytearray在处理二进制数据时非常有用,尤其是在需要对数据进行修改的情况下。它结合了列表的可变性和字节字符串的高效存储,是一个灵活且强大的工具。
创建bytearray, 并对其内部的元素增加,删除, 字符串decode操作。
from m5stack import *
from m5stack_ui import *
from uiflow import *
screen = M5Screen()
screen.clean_screen()
screen.set_screen_bg_color(0xFFFFFF)
bytes2 = None
bytes2 = bytearray(5)
bytes2[0] = 104
bytes2[1] = 101
bytes2[2] = 108
bytes2[3] = 108
bytes2[4] = 111
bytes2.append(33)
print(bytes2.decode(bytes2))
print(bytes2[5])
bytes2 = bytearray(5)
bytes2[0] = 104
bytes2.append(33)
print(bytes2.decode('utf-8'))