Python ord(), chr() and String Operations
PCAP objective 3.2 is operate on strings, and its distinctive content is ord and chr - the two functions that turn a character into its code point and back. They are examined through arithmetic: shifting letters, converting case by adding 32, and the comparison order that falls out of the ranges. The classic exercise is a Caesar cipher, and this guide runs one.
Strings in Depth Guide 10 of 25 Intermediate
- OSUbuntu 26.04 LTS
- Python3.14.4
- pip25.1.1
- TimeAbout 15 min
Nothing here has changed in Python 3. chr() accepts the full Unicode range up to 0x10FFFF; in Python 2 the equivalent function unichr was separate and narrower.
| 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 |
This guide includes
Use this for the string-operations objective. This matters because its distinctive content is arithmetic on code points - a Caesar shift, and case conversion done by adding a constant.
- using
ordandchras inverses - learning the three ranges, and the gap between them
- meeting four ways these two refuse
- writing a Caesar shift, which is what this objective exists for
- converting case by arithmetic, and using the operators on strings
Before you start
-
ord and chr are inverses
-
The three ranges, and the gap between them
-
How ord and chr refuse
-
A Caesar shift, which is what this objective is for
-
Case conversion is arithmetic
-
The operators, on strings
-
What the exam does with this objective