PCAP · Domain 3 of 5

PCAP Domain 3: Strings

Section 3 covers how Python stores and manipulates text: character encodings and code points, indexing and slicing immutable strings, comparison and membership, and the built-in methods and sorted() calls that PCAP snippets use constantly.

Exam weight
18%
Official objectives
3
Estimated questions estimate
~8
Suggested study time estimate
8–12 hrs

About 11 min read Reviewed October 2026

Overview

Strings is Section 3 of the PCAP-31-03 syllabus, with three objectives. Understanding machine representation of characters covers ASCII, Unicode and UTF-8, code points and escape sequences. Operating on strings covers ord() and chr(), indexing, slicing, immutability, iteration, concatenation with +, repetition with *, lexicographic comparison and the in and not in operators. Employing built-in string methods covers the isxxx() family such as isalpha(), isdigit(), isalnum(), isspace(), isupper() and islower(), plus join(), split(), strip(), index(), find() and rfind(), along with the sorted() function for ordering strings.

Python 3 strings are immutable sequences of Unicode code points. That one sentence explains most exam behavior: indexing returns one-character strings, assignment to an index fails, every method returns a new string, and comparisons follow code point values. Short snippets in this section often chain two or three operations, so precise knowledge of each return value is essential.

How it's tested

String items are almost always output predictions. A snippet slices, compares, splits or joins text, and you choose the exact printed result, including quotes, brackets, empty strings and negative numbers. Some items ask which line raises an error, which usually tests immutability, a join() call on non-strings or index() on a missing value.

  • Slice arithmetic

    A slice with negative indices or a step is applied, and you choose the exact substring it produces.

  • Method return values

    A method such as split(), find() or strip() is called, and you identify the returned type and value.

  • Character ordering

    Strings are compared or sorted, and you apply code point order rather than numeric or dictionary intuition.

Reasoning it through

A snippet prints 'banana'.rfind('a') and 'banana'.find('n'). rfind() searches from the right but still reports an index counted from the left, so the last 'a' is at position 5. find() returns the first 'n' at position 2. Candidates who count from the right for rfind() choose 0 or 1 instead, so remember that only the search direction changes, not the numbering.

Objectives 3

Official objectives from the OpenEDG Python Institute outline, in outline order.

3.1 Understand machine representation of charactersASCII, Unicode, UTF-8, code points and escape sequences.
What it means
This objective covers how characters become numbers in memory: the character sets and encodings Python relies on, the code point that identifies each character, and escape sequences for characters that are hard to type.
What to understand
ASCII defines 128 characters with code points 0 to 127. Unicode assigns a code point to characters from almost every writing system and keeps ASCII as its first 128 entries. UTF-8 is a variable-length encoding that stores each code point in one to four bytes, with ASCII characters taking one byte. Escape sequences such as \n, \t, \\ and \' each represent a single character, so len('\n') is 1.
How it shows up
Expect questions on how many characters an escaped literal holds or which encoding is variable length.
Common confusion
Confusing Unicode, a character set of code points, with UTF-8, one way of encoding those code points as bytes.
3.2 Operate on stringsord(), chr(), indexing, slicing, immutability, iteration, concatenation, repetition, comparisons, in and not in.
What it means
This objective covers the operators and built-in functions that act on whole strings or individual characters without calling string methods.
What to understand
ord() returns a character's code point and chr() reverses it, so ord('a') is 97 and chr(65) is 'A'. Indexing and slicing work as for lists, including negative indices and steps such as s[::-1]. Strings are immutable, so s[0] = 'x' raises TypeError. + concatenates, * repeats, and multiplying by zero gives an empty string. Comparison is lexicographic by code point, which makes '10' < '9' and 'Z' < 'a' both true. in tests for substrings.
How it shows up
Items combine slicing, ord() or comparisons in one print call and ask for the full output line.
Common confusion
Comparing numeric-looking strings as numbers; Python compares them character by character using code points.
3.3 Employ built-in string methodsisxxx() methods, join(), split(), strip(), index(), find(), rfind() and sorted().
What it means
This objective covers the methods PCAP expects you to use without documentation, along with sorted() for ordering the characters of a string or a list of strings.
What to understand
The isxxx() methods return False for an empty string. split() without an argument splits on runs of whitespace and drops empty pieces, while split(',') keeps empty strings between adjacent separators. join() is called on the separator and needs an iterable of strings. strip() removes any combination of the given characters from both ends. find() and rfind() return -1 when nothing matches, but index() raises ValueError. sorted('cab') returns the list ['a', 'b', 'c'].
How it shows up
Expect snippets that print the result of split() or sorted() and test whether you know the list output format.
Common confusion
Calling join() on the list, as in list.join('-'); the method belongs to the separator string.

High-yield concepts

The terms, rules and formulas this domain turns into questions most often.

  • Code point

    The integer Unicode assigns to a character.

    Remember
    ord() returns it; chr() converts back.
    Tested as
    ord() and chr() output items.
    Trap
    Mixing up the direction of the two functions.
  • UTF-8

    Variable-length encoding of Unicode using one to four bytes per code point.

    Remember
    ASCII characters use one byte.
    Tested as
    Encoding theory questions.
    Trap
    Calling UTF-8 a fixed two-byte encoding.
  • Escape sequence

    A backslash combination representing one character.

    Remember
    len('\n') is 1.
    Tested as
    Length questions.
    Trap
    Counting the backslash as a separate character.
  • Immutability

    Strings cannot change after creation.

    Remember
    Index assignment raises TypeError.
    Tested as
    Which-line-fails items.
    Trap
    Expecting s[0] = 'x' to work like a list.
  • Slicing with steps

    s[start:stop:step] extracts characters; the stop index is excluded.

    Remember
    s[::-1] reverses the string.
    Tested as
    Output prediction.
    Trap
    Including the stop position in the result.
  • Lexicographic comparison

    Strings are compared character by character by code point.

    Remember
    Uppercase letters sort before lowercase letters.
    Tested as
    Comparison and sorting items.
    Trap
    Comparing digit strings numerically.
  • in operator

    Tests whether one string appears inside another.

    Remember
    '' in 'abc' is True.
    Tested as
    Membership items.
    Trap
    Thinking in checks only single characters.
  • Repetition

    s * n repeats a string n times.

    Remember
    A zero or negative n gives ''.
    Tested as
    Output items.
    Trap
    Expecting an error for a zero multiplier.
  • split()

    Breaks a string into a list of substrings.

    Remember
    No argument splits on whitespace runs and drops empty strings.
    Tested as
    Output format items.
    Trap
    Expecting empty strings from split() without arguments.
  • join()

    Concatenates strings from an iterable with the separator between them.

    Remember
    All elements must be strings.
    Tested as
    TypeError and output items.
    Trap
    Passing a list of integers.
  • find() vs. index()

    Both locate a substring; they differ when it is missing.

    Remember
    find() returns -1; index() raises ValueError.
    Tested as
    Error versus value items.
    Trap
    Expecting index() to return -1.
  • strip()

    Removes leading and trailing characters from a given set.

    Remember
    The argument is a set of characters, not a prefix.
    Tested as
    Output items.
    Trap
    Expecting it to remove characters in the middle.
  • sorted() on a string

    Returns a new list of the string's characters in order.

    Remember
    The result is a list, not a string.
    Tested as
    Output format items.
    Trap
    Calling s.sort(), which does not exist for strings.

Side by side

Concepts candidates mix up, compared on the point that decides the answer.

Searching for a substring

ConceptMeaningKey differenceCommon trap
find() First index of a match Returns -1 when missing Expecting an exception
rfind() Last index of a match Index still counted from the left Counting from the right
index() First index of a match Raises ValueError when missing Expecting -1
in Boolean membership test Returns True or False only Expecting a position

Character representation

ConceptMeaningKey differenceCommon trap
ASCII 128 characters, codes 0 to 127 Subset of Unicode Assuming it covers accented letters
Unicode Code points for most writing systems A character set, not a byte format Calling it an encoding
UTF-8 Encoding of code points into bytes One to four bytes per character Assuming a fixed width

split() variants

ConceptMeaningKey differenceCommon trap
'a b'.split() Splits on whitespace runs Result ['a', 'b'] Expecting an empty string between
'a,,b'.split(',') Splits on each comma Result ['a', '', 'b'] Dropping the empty string
''.split() Splits an empty string Result [] Expecting ['']

Exam traps

Each trap is an answer that looks right. Learn the clue that should change your mind.

  1. Numeric string order

    What candidates pick
    Answer False for '10' < '9'.
    Why it looks right
    Ten is larger than nine.
    Why it's wrong
    Strings compare by code point, and '1' comes before '9', so the result is True.

    Clue to watch for Both operands are quoted digits.

  2. Case-insensitive sorting

    What candidates pick
    Expect sorted(['b', 'B', 'a']) to return ['a', 'b', 'B'].
    Why it looks right
    Dictionary order ignores case.
    Why it's wrong
    Uppercase code points are lower, so the result is ['B', 'a', 'b'].

    Clue to watch for The list mixes uppercase and lowercase strings.

  3. Strip removes a word

    What candidates pick
    Assume 'xxhixx'.strip('x') removes only one x from each end.
    Why it looks right
    The argument looks like a prefix to remove.
    Why it's wrong
    strip() removes every leading and trailing character found in the argument set, giving 'hi'.

    Clue to watch for The same character repeats at both ends.

  4. Empty string digits

    What candidates pick
    Answer True for ''.isdigit().
    Why it looks right
    No characters means nothing violates the rule.
    Why it's wrong
    All isxxx() methods return False for an empty string.

    Clue to watch for The method is called on ''.

  5. join on integers

    What candidates pick
    Choose '1-2' for '-'.join([1, 2]).
    Why it looks right
    join() looks like it formats any values.
    Why it's wrong
    join() accepts only strings and raises TypeError for integer elements.

    Clue to watch for The iterable holds numbers, not quoted values.

  6. Mutable character

    What candidates pick
    Pick a modified string after s[0] = 'J'.
    Why it looks right
    Lists allow index assignment.
    Why it's wrong
    Strings are immutable, so this line raises TypeError.

    Clue to watch for A snippet assigns to a string index.

Answer framework

For a Section 3 snippet, apply these steps to reach the exact output PCAP-31-03 expects.

  1. Write the string out with its index numbers, both positive and negative, before evaluating any indexing or slicing.
  2. Apply slices with the stop index excluded and the step direction respected, then check whether the result could be empty.
  3. For each method call, decide the return type first, such as a string, list, integer or Boolean, then the value, since find() returns -1 where index() raises ValueError.
  4. For comparisons and sorting, compare code points character by character, remembering digits sort before uppercase and uppercase before lowercase.
  5. Check for error lines such as index assignment, index() on a missing substring or join() over non-strings before choosing a printed value.

Practice question

A sorting helper compares numeric strings and mixed-case letters, then searches for a character that is absent. What is the output of the following line? print('10' < '9', 'Z' < 'a', 'abc'.find('z'))

Choose one answer

Want more like this? The PCAP practice test has questions for every domain.

Checklist

0 of 13

Tick each one you can do without notes. Your ticks stay in this browser.

Study strategy

Begin with representation, because it explains the rest. Use ord() and chr() on letters, digits, a space and an accented character, and note the numbers. Encode a few strings to UTF-8 and compare the byte length with len() of the string. Write literals with escape sequences and check their lengths.

Next, practice operations on paper before typing them. Take a word such as 'Python', write its positive and negative indices, and predict ten slices, including reversed ones and slices that come out empty. Then run them. Do the same for comparisons, mixing digits, capitals and lowercase letters, and confirm with sorted().

Then work through the methods listed in the syllabus. For each one, record its return type, its behavior with an empty string and its failure mode. Pay extra attention to split() with and without arguments, strip() with a character set and the find() versus index() difference.

Finally, mix these into chained one-liners like the exam uses, for example a slice followed by upper() and a comparison, and time yourself. Eight items depend on this section, so aim for near-automatic accuracy.

FAQ

How much of PCAP is Section 3, Strings?

Strings is 18% of PCAP-31-03, and the official syllabus assigns it 8 of the 40 exam items.

Why is '10' < '9' True in Python?

Strings compare character by character using code points. The first characters are '1' and '9', and '1' is smaller, so the comparison ends there.

What is the difference between find() and index()?

Both return the lowest index of a substring. When it is missing, find() returns -1 and index() raises ValueError.

Is UTF-8 the same as Unicode?

No. Unicode assigns code points to characters, and UTF-8 is an encoding that stores those code points in one to four bytes.

Can I change one character of a string?

Not in place. Strings are immutable, so you build a new string, for example with slicing and concatenation.

What does sorted('cab') return?

The list ['a', 'b', 'c']. Use ''.join(sorted('cab')) if you need a string back.

Which isxxx() methods should I know?

The syllabus lists the group as .isxxx(); practice isalpha(), isdigit(), isalnum(), isspace(), isupper() and islower(), and remember they all return False for ''.

Test your Domain 3 knowledge

You have covered encodings, code points, slicing, comparisons and the string methods in the syllabus. Test whether you can predict exact outputs quickly.

Keep going