Python bytes Data Type

Created with Sketch.

bytes Data Type

bytes data type represents a group of byte numbers just like an array.

 x = [10,20,30,40] 
 b = bytes(x) 
 type(b)bytes 
 print(b[0])10
 print(b[-1])40 
 >>> for i in b : print(i) 
 
 10 
 20 
 30 
 40

Conclusion 1:


The only allowed values for byte data type are 0 to 256. By mistake, if we are trying to
provide any other values then we will get a value error.


Conclusion 2:


Once we create a bytes data type value, we cannot change its values, otherwise, we will get
TypeError.

 >>> x=[10,20,30,40] 
 >>> b=bytes(x) 
 >>> b[0]=100 
 TypeError: 'bytes' object does not support item assignment 

Leave a Reply

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