bytearray Data type in Python

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


Example:

>>>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


Example:

>>> x =[10,256]

>>> b= bytearray(x)

ValueError: byte must be in range(0,256)


No comments:

Post a Comment

Thank you Very Much.For Given Comment

Conversion from Decimal to other Number Systems

 ==>To convert a decimal number to any other number system (binary, octal or hexadecimal), use the steps given below. Step 1: Divide the ...