Courseiva
Strings →hardMultiple Choice

PCAP Strings Practice Question

Exhibit

Refer to the exhibit.

path = r"C:\Users\John\Documents"
print(len(path))

Given the code above, what is printed? Note: each backslash is a single character.

⚠ Common exam trap

The PCAP exam often tests the misconception that escape sequences like `\n` or `\t` are counted as single characters, when in fact each backslash is a separate character unless the string uses raw notation.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

23

The string "C:\\Users\\John\\Documents" uses double backslashes to represent literal backslashes. Each double backslash `\\` is a single backslash character. Counting all characters: C, :, \, U, s, e, r, s, \, J, o, h, n, \, D, o, c, u, m, e, n, t, s = 23 characters. Thus, the length is 23.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    21

    Why it's wrong here

    Selecting 21 would result from incorrectly assuming that two of the backslashes act as escape sequences and merge with the next character into a single character. In a raw string like the one shown, every backslash is literally included, so the actual string has three backslashes and 23 characters; dropping two of those backslashes numerically yields 21.

  • ✓

    23

    Why this is correct

    The string `C:\Users\John\Documents` (written as a raw string) contains 23 characters: `C`, `:`, `\`, `U`, `s`, `e`, `r`, `s`, `\`, `J`, `o`, `h`, `n`, `\`, `D`, `o`, `c`, `u`, `m`, `e`, `n`, `t`, `s`. Because it is a raw string, each backslash is its own character and none of the letters are escaped, so `len()` on this literal returns exactly 23.

  • ✗

    22

    Why it's wrong here

    A count of 22 is one short, most likely from forgetting to count the second backslash or the final `s` in `Documents`. The raw string preserves all three backslashes, so any count that excludes a single visible character (such as the backslash immediately before `Documents`) will be off by one and fail to match `len()`.

  • ✗

    24

    Why it's wrong here

    A count of 24 would mean you added an extra character that does not exist in the literal. For example, counting the raw string prefix `r` or the surrounding quotes as part of the string value would inflate the length by one or two, and even adding just the `r` prefix gives 24. The value itself contains only the drive, path separators, and directory names, with no trailing slash or blank space.

About these practice questions

One of 421 original PCAP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.