How to insert a value at specific index into bytearray with Python

1 Answer

0 votes
arr = bytearray()

arr.append(0)
arr.append(1)
arr.append(2)
arr.append(3)
arr.append(4)

print(arr)

arr.insert(1, 255)

print(arr)

'''
run:

bytearray(b'\x00\x01\x02\x03\x04')
bytearray(b'\x00\xff\x01\x02\x03\x04')

'''

 



answered Sep 7, 2018 by avibootz

Related questions

1 answer 270 views
1 answer 197 views
1 answer 200 views
1 answer 225 views
1 answer 184 views
1 answer 148 views
...