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 258 views
1 answer 189 views
1 answer 191 views
1 answer 209 views
1 answer 178 views
1 answer 139 views
...