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 167 views
1 answer 140 views
1 answer 146 views
1 answer 129 views
1 answer 139 views
1 answer 103 views
...