Python String Basics
Objective 3.4 asks you to operate with strings, and a string is an immutable sequence of characters - so every index and slice rule from the list guides applies, and nothing can be assigned. What is new is the method list, and one method that behaves differently depending on whether you give it an argument: split() and split(" ") produce different results on the same input.
Data Collections Guide 17 of 26 Beginner
- OSUbuntu 26.04 LTS
- Python3.14.4
- pip25.1.1
- TimeAbout 18 min
Strings have been Unicode by default since Python 3.0, and there is no separate character type. PCAP goes further into encodings and code points - see guide 9. Nothing on this page has changed in Python 3.
| 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 objective. This matters because a string is immutable, so every method hands back a new string - and s += "d" only looks like it changes s in place.
- treating a string as a sequence, and seeing what immutability rules out
- finding that rebinding is not mutating
- using the methods the objective names, and what a missing substring raises
- using
splitandjoin, including the one call that raises - comparing by code point, and putting values into a string four ways
Before you start
-
A string is a sequence
-
What immutability rules out
-
Rebinding is not mutating
-
Quoting, and the literals that join themselves
-
The methods the objective names
-
index() on a missing substring
-
split and join, and the argument that changes everything
-
split with an empty separator
-
Comparison is by code point
-
Putting values into a string
-
What the exam does with this objective