Introduction To “Byte”
2 min readAug 10
--
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.
“Bytes” 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 “Python Bytes” are “Created”?
- “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”.
“Operations” on “Bytes”
- “Bytes” in “Python” support “Most” of the “Same Operations” as “String”.
“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”.
“Splitting” of “Bytes”
- The “Split” Operation on the “Bytes” “Returns” a “List” of “Byte Objects”.
- The “Split” Operation is “Performed” using the “split ()” Method on the “Sequence of Bytes Object”.