PCAP Strings Practice Question
Which TWO of the following string methods return a new string without modifying the original?
⚠ Common exam trap
Python Institute often tests the distinction between methods that return a new string (like `replace()` and `strip()`) versus those that return an index or count (like `index()`, `find()`, and `count()`), trapping candidates who confuse 'returning a value' with 'returning a new string'.
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
✓
replace()
The `replace()` method returns a new string with all occurrences of a substring replaced by another substring, without altering the original string. Similarly, `strip()` returns a new string with leading and trailing whitespace (or specified characters) removed, leaving the original unchanged. Both methods are non-mutating because strings in Python are immutable.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
index()
Why it's wrong here
The index() method searches for a given substring and returns the lowest integer index at which it occurs, raising a ValueError if the substring is not found. This return value is a position in the original string, not a transformed copy. Because it does not produce a new string object, it does not satisfy the requirement of returning a new string.
- ✓
replace()
Why this is correct
The replace() method takes two substrings and returns a brand-new string in which all non-overlapping occurrences of the first substring have been replaced with the second. Since strings are immutable, the original string is untouched; instead, the method constructs a new string and returns it. This precisely matches the condition of returning a new string.
- ✓
strip()
Why this is correct
The strip() method returns a new string with leading and trailing whitespace removed, or with a specified set of characters removed if given as an argument. It does not alter the original string, because strings are immutable; rather, it copies the relevant portion into a fresh string object. This makes it one of the string methods that correctly returns a new string.
- ✗
find()
Why it's wrong here
The find() method returns the lowest integer index where a given substring appears, or -1 if the substring is absent. It is similar to index() but does not raise an exception on failure; however, both return an integer, not a string. Since it only reports a numeric position and never constructs a new string, it is not a correct answer.
- ✗
count()
Why it's wrong here
The count() method counts how many times a specified substring occurs non-overlapping within the original string and returns that number as an integer. It performs analysis rather than transformation, so it never creates or returns a new string object. Thus, it fails the requirement that the method returns a new string.
Go deeper
Related to this question
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 →
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.