bytearray 타입은 bytes에서 원하는 위치에 있는 값을 바꿀 수 있는 가변(mutable) 버전과 같다. 인덱스를 사용해 bytearray의 내용을 바꿀 때는 바이트 문자열(한 글자짜리)이 아니라 정수를 대입한다.
my_array = bytearray(b"hello")
my_array[0] = 0x79
print(my_array)
>>>
bytearray(b'yello')
bytearray 타입은 bytes에서 원하는 위치에 있는 값을 바꿀 수 있는 가변(mutable) 버전과 같다. 인덱스를 사용해 bytearray의 내용을 바꿀 때는 바이트 문자열(한 글자짜리)이 아니라 정수를 대입한다.
my_array = bytearray(b"hello")
my_array[0] = 0x79
print(my_array)
>>>
bytearray(b'yello')