PCAP Strings Practice Question
Which TWO of the following are valid string methods in Python?
⚠ Common exam trap
Python Institute often tests the candidate's understanding of string immutability versus list mutability, leading candidates to mistakenly assume that methods like `reverse()` or `shuffle()` apply to strings because they seem intuitive for sequence manipulation.
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
✓
capitalize()
`capitalize()` is a built-in string method in Python that returns a copy of the string with its first character capitalized and the rest lowercased. It is part of the standard string methods available for all string objects in Python.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
capitalize()
Why this is correct
capitalize() is a valid string method that creates and returns a new string with the first character converted to uppercase and all remaining characters converted to lowercase. Because strings are immutable, the original string is not modified, and the method call produces a copy. If the first character is not a letter (e.g., a digit or symbol), it remains unchanged while the rest of the string is lowercased.
- ✗
rotate()
Why it's wrong here
rotate() is not a defined method on Python string objects. While rotation of characters in a string is a common operation, you must achieve it manually using slicing, such as s[1:] + s[:1], or by using collections.deque for rotation-like behavior. Attempting to call 'some_string'.rotate() raises an AttributeError because the str class has no such method.
- ✗
shuffle()
Why it's wrong here
shuffle() is not a string method; it is a function available in the random module that randomly reorders a mutable sequence like a list. Since strings are immutable, Python does not provide a shuffle() method on str, and calling it on a string would raise an AttributeError. To shuffle characters, you would need to convert the string to a list, apply random.shuffle(), and then join the list back into a string.
- ✓
swapcase()
Why this is correct
swapcase() is a valid string method that returns a new string where every uppercase alphabetic character is converted to lowercase and every lowercase alphabetic character is converted to uppercase. Non-alphabetic characters, such as spaces or digits, remain exactly as they were. This method is useful for scenario-based case transformations and does not alter the original string due to immutability.
- ✗
reverse()
Why it's wrong here
reverse() is not a method of Python strings; it exists only on list objects as a built-in method that reverses the elements in place. Strings are immutable, so they cannot provide an in-place reverse operation. To reverse a string, you use slicing with a step of -1 (e.g., s[::-1]) or convert the string to a list, use reversed(), and join the result.
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.