PCAP Strings Practice Question
A developer wants to check if a string 'racecar' is a palindrome by comparing it to its reverse. Which code completes the task correctly?
⚠ Common exam trap
The PCAP exam often tests the distinction between `reversed()` (which returns an iterator) and `[::-1]` (which returns a reversed sequence), and the fact that strings are immutable and lack a `.reverse()` method, leading candidates to confuse list methods with string operations.
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
✓
s[::-1] == s
The slicing syntax `s[::-1]` creates a reversed copy of the string `s`, and comparing it to `s` with `==` checks if the string reads the same forwards and backwards, which is the definition of a palindrome. For the string 'racecar', `s[::-1]` returns 'racecar', so the comparison is `True`.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
reversed(s) == s
Why it's wrong here
reversed(s) returns a reverse iterator, not a string. Comparing an iterator object directly to a str with == is always False, because the types do not define cross-type equality. Even though ''.join(reversed(s)) would correctly produce 'racecar', the raw reversed(s) itself is a lazy iterator, so this expression never detects a palindrome.
- ✗
s[::1] == s
Why it's wrong here
The slice s[::1] uses a positive step of 1, so it simply returns the original string unchanged, not reversed. Consequently, s[::1] == s is always True for any string, making it useless as a palindrome test. To reverse via slicing, the step must be negative, as in s[::-1].
- ✓
s[::-1] == s
Why this is correct
The slice s[::-1] uses a negative step with default start and end, which makes Python traverse the string from the last character back to the first, producing the reversed string. Comparing this reversed result to the original string with == correctly determines whether s reads the same forward and backward, i.e., whether it is a palindrome.
- ✗
s.reverse() == s
Why it's wrong here
String objects in Python do not have a .reverse() method, so calling s.reverse() raises an AttributeError immediately. Even if it did exist, strings are immutable, so no in-place reversal could modify the original string. The list method list.reverse() works in place and returns None, but it is not applicable to str objects.
Visual reference
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.