bytes
An immutable sequence of small integers from 0 to 255, the raw form of encoded text and binary data.
In more detail
str.encode() returns bytes and bytes.decode() returns a string. A byte is eight bits, and UTF-8 uses one to four bytes for each character. Literals are written with a b prefix, such as b'A'.
Example
print('\u00e9'.encode('utf-8')) # b'\xc3\xa9'Related terms
- bytearray — A changeable sequence of bytes, often used as a buffer for binary input and output.
- UTF-8 — The most widely used character encoding, which can represent every Unicode character and matches ASCII for plain English letters.
- binary mode — Opening a file with b in its mode, so reads return bytes exactly as stored.
Taught in
- The Class That Shared One List — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Characters As Numbers — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Strings Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Streams, Handles And Open Modes — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- read, readline, errno And bytearray — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Comprehensions, Closures And Files Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Mock, Review And Exam Day — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep