Python byte array Data Type (PYTHON FUNDAMENTALS)

python tutorials and learn python

Created with Sketch.

bytearray is exactly same as bytes data type except that its elements can be
modified.

 x=[10,20,30,40] 
 b = bytearray(x) 
 for i in b : print(i) 
 10 
 20 
 30 
 40 
 b[0]=100 
 for i in b: print(i) 
 100 
 20 
 30 
 40

Eg 2:

>>> x =[10,256] 
>>> b = bytearray(x) 
ValueError: byte must be in range(0, 256) 

Leave a Reply

Your email address will not be published. Required fields are marked *