pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Bytearray

bytearray is a built-in mutable sequence type in Python for working with byte data. It is similar to the bytes type, but differs in that bytearray is mutable, whereas bytes is immutable. bytearray is very useful when working with binary data, especially if the data needs to be modified. It combines the mutability of lists with the efficient storage of byte strings, making it a flexible and powerful tool.

Example

Creates a bytearray, and adds, removes, and decodes elements within it

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])

API

bytes2 = bytearray(5)
  • Creates a bytearray of the specified length
bytes2[0] = 104
  • bytearray Specify index assignment
bytes2.append(33)
  • Adds a byte to the end of the bytearray
print(bytes2.decode('utf-8'))
  • bytearray string decoding
On This Page