0% found this document useful (0 votes)
6 views2 pages

Bytes Data Type

'bytes' is a pre-defined class in Python treated as a sequence type, primarily used for implementing end-to-end encryption of data for security. It utilizes numerical integer values ranging from 0 to 255, and while it maintains insertion order and supports indexing and slicing, it is immutable, meaning items cannot be assigned. The document includes examples demonstrating the creation of bytes objects and the resulting errors when values are out of range.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Bytes Data Type

'bytes' is a pre-defined class in Python treated as a sequence type, primarily used for implementing end-to-end encryption of data for security. It utilizes numerical integer values ranging from 0 to 255, and while it maintains insertion order and supports indexing and slicing, it is immutable, meaning items cannot be assigned. The document includes examples demonstrating the creation of bytes objects and the resulting errors when values are out of range.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

=========================================================

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

You might also like