Sitemap

Introduction To Byte Data Type

2 min readAug 10, 2023

When Byte is Used?

The files, and, the network resources, such as — HTTP Responses are transmitted as Byte Streams.

To read and decode such files, and, HTTP Responses using Python, the Byte data type is used.

What is Byte in Python?

Bytes are very similar to the Strings.

Whereas Strings are the Sequences of Unicode Code Points, the Bytes are the Sequences of Bytes.

Bytes are useful for Raw Binary data and Fixed-Width Single-Byte Character Encoding, such as, ASCII.

How Bytes are Created in Python?

Literal Bytes in Python are delimited by quotes.

Both of the single quotes and the double quotes can be used.

The quote is prefixed by a lowercase b.

Create a Literal Byte Using Single Quote
Create a Literal Byte Using Double Quote

Different Operations on Byte Data Type

Bytes in Python support most of the same operations as String.

1. Indexing of Bytes

Indexing of Bytes returns the integer value of the Byte, that is present at the specified Index.

In the below example, the integer value of the Byte character that is present in the Third Index of the Byte Stream is 110, i.e., the ASCII Value of the English letter n.

Print the Integer Value of the Third Byte, i.e., Index=2 from a Sequence of Bytes

2. Splitting of Bytes

The split operation on the Byte data type returns a List of Byte objects.

The split operation is performed using the split () method on the Sequence of Byte objects.

Split a Sequence of Bytes

--

--

Oindrila Chakraborty
Oindrila Chakraborty

Written by Oindrila Chakraborty

I have 13+ experience in IT industry. I love to learn about the data and work with data. I am happy to share my knowledge with all. Hope this will be of help.

No responses yet