Python Encodings and Code Points
PCAP objective 3.1 is understand machine representation of characters, and it is the one string objective that is really about types. A `str` is a sequence of **code points**; a `bytes` is a sequence of numbers 0-255. `encode` turns the first into the second and `decode` goes back, and the two lengths do not have to match - `café` is four characters and five UTF-8 bytes. Everything else in the objective follows from that.
Strings in Depth Guide 9 of 25 Intermediate
- Python3.14.4
- OSUbuntu 26.04 LTS
- pip25.1.1
- TimeAbout 17 min
- Reviewed23 August 2026
Written against the versions above. Python 3 made `str` Unicode and `bytes` a separate type, which is the single largest Python 2 to 3 change. Anything using `unicode(...)` or `str.decode()` is Python 2. The default source encoding is UTF-8 and has been since 3.0.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Python 3.14.4 - the only machine this path needs | 2 Core | 4 GB | 50 GB |
Before you start
-
A string is a sequence of code points
-
str and bytes are different types
-
The same text in three encodings
-
How encoding and decoding fail
-
The same bytes read two ways
-
What bytes actually contain
-
ASCII, and the default
-
What the exam does with this objective