bytes Data Type:
bytes data type represents a group of byte numbers just like an array.
The only allowed values in bytes data type are in range of 0- 256
example:
x=[10,20,30,40,50]
b=bytes(x)
type(b)----> bytes
You can save numbers in bytes datatype object but only in a particular range(0,256)
If you try to save a number out of this range you will get ValueError:
In Python if you talk about range(0,256) you mean the allowed numbers are 0 to 255 , Therefore even 256 is not allowed in bytes
bytes is IMMUTABLE
therefore item assignment is not allowed
therefore item assignment is not allowed
If you try so, you will get TypeError
bytearray Data type:
bytearray is exactly same as bytes data type except that its elements can be modified.
No comments:
Post a Comment