CKTIS / Python
bytearray()
Erzeugt ein veränderliches Bytefeld.
Version: Python 3.14; repository image, production runtime not attested
Syntax
bytearray()
bytearray(source)
bytearray(string, encoding, errors="strict")Erzeugt ein veränderliches Bytefeld.
Die Zuweisung von 65 an Position null ersetzt das erste a durch A, also enthält bytes(data) Abc. Der Konstruktor mit 3 erzeugt drei Nullbytes.
Die Zuweisung eines Werts außerhalb von 0–255 löst ValueError aus.
data = bytearray(b"abc")
alias = data
data[0] = 65
assert bytes(alias) == b"Abc" and bytearray(3).hex() == "000000"
Beispiele
data = bytearray(b"abc")
data[0] = 65
print(bytes(data))
print(bytearray(3).hex())
Ergebnis
b'Abc' 000000
Die Zuweisung eines Werts außerhalb von 0–255 löst ValueError aus.