=========================================================
2. bytes
=========================================================
=>Here 'bytes' is one of the Pre-Defined Class and treated as Sequence Type.
=>The Purpose of 'bytes' data type is that "To Implement End-to-End Encryption of
Data between two ends for getting
Security."
=>To Implement End-to-End Encryption of Data between two ends for getting Security
by using bytes data, bytes data
type uses the Numerical Integer Values ranges from (0,256).
=>Programatically, There is no Symbolic Notation for Representing bytes data. But
we can convert Other Types of Values
into bytes type by using bytes().
Syntax: varname=bytes(Object)
=>An object of bytes Maintains Insertion order. Nothing but What ever the Order we
organize the data, In the same order
the data will be displayed.
=>On the Object of bytes, we can perform Both Indexing and Slicing Operations.
=>An Object of bytes belongs to IMMUTABLE bcoz 'bytes' object does not support item
assignment
-----------------------------------------------------------------------------------
-------------------------------------------------------------
Examples
-----------------------------------------------------------------------------------
-------------------------------------------------------------
>>> lst=[146,167,233,256,0,199,221,189]
>>> print(lst,type(lst))---------------[146, 167, 233, 256, 0, 199, 221, 189]
<class 'list'>
>>> b=bytes(lst)-----------------------ValueError: bytes must be in range(0, 256)
-------------------
>>> lst=[146,-167,233,255,0,199,221,189]
>>> print(lst,type(lst))-------------[146, -167, 233, 255, 0, 199, 221, 189] <class
'list'>
>>> b=bytes(lst)-----------------------ValueError: bytes must be in range(0, 256)
------------------------------------------------
>>> lst=[146,167,233,255,0,199,221,189]
>>> print(lst,type(lst))-----------------------[146, 167, 233, 255, 0, 199, 221,
189] <class 'list'>
>>> b=bytes(lst)
>>> print(b,type(b))---------------------------b'\x92\xa7\xe9\xff\x00\xc7\xdd\xbd'
<class 'bytes'>
>>> for val in b:
... print(val)
...
146
167
233
255
0
199
221
189
>>> b[0]------------------------------146
>>> b[-1]------------------------------189
>>> for val in b[2:5]:
... print(val)
...
233
255
0
-------------------------
>>> b[0]
146
>>> b[0]=233----------------TypeError: 'bytes' object does not support item
assignment--IMMUTABLE
>>>