Courseiva

PCAP · topic practice

Strings practice questions

Practise Certified Associate Python Programmer PCAP Strings practice questions — original exam-style scenarios with answer choices, explanations, and analysis of common mistakes.

Courseiva uses original exam-style practice questions designed for learning and revision. The goal is to understand the concepts, recognise exam patterns, and improve through explanations — not memorise copied exam dumps.

Reviewed byJohnson Ajibi· MSc IT Security
19 questionsDomain: Strings

What the exam tests

What to know about Strings

Strings questions test whether you can apply the concept in context, not just recognise a definition.

How the topic appears in realistic exam-style scenarios.

Which detail in the question changes the correct answer.

How to eliminate plausible but wrong options.

How to connect the question back to the wider exam objective.

Watch out for

Common Strings exam traps

  • Answering from memory before reading the full scenario.
  • Missing a constraint such as cost, availability, security, scope or command context.
  • Choosing a broad answer when the question asks for the most specific fix.
  • Ignoring why the wrong options are tempting.

Practice set

Strings questions

19 questions · select your answer, then reveal the explanation

Question 1mediummultiple choice
Read the full Strings explanation →

A programmer writes a function to check if a string is a palindrome (ignoring case and non-alphanumeric characters). Which implementation correctly achieves this?

Question 2hardmultiple choice
Read the full Strings explanation →

A log analysis script needs to extract all IP addresses from a string. The IPs are in dotted-decimal format. Which regex pattern will correctly extract them?

Question 3easymultiple choice
Read the full Strings explanation →

Which string method can be used to check if a string contains only digits?

Question 4mediummultiple choice
Read the full Strings explanation →

A developer needs to replace all occurrences of 'cat' with 'dog' in a string, but only if 'cat' is a whole word (not part of 'category'). Which code achieves this?

Question 5hardmultiple choice
Read the full Strings explanation →

Given the string s = 'Hello World!', which expression returns a list of characters?

Question 6easymultiple choice
Read the full Strings explanation →

Which of the following is the correct way to format a string with variables?

Question 7mediummultiple choice
Study the full Python automation breakdown →

What is the result of 'Python'.find('th')?

Question 8hardmultiple choice
Read the full Strings explanation →

Which of the following methods can be used to check if a string starts with a vowel?

Which TWO statements are true regarding strings in Python?

Which THREE are valid escape sequences in Python strings?

Question 11mediummultiple choice
Read the full Strings explanation →

Given s = 'Hello\nWorld!\n\n\n\n\n\n', what is the length of string s?

Exhibit

Refer to the exhibit.

Error log:
```
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    print(s[15])
IndexError: string index out of range
```

Code:
```python
s = "Python Programming"
print(s[15])
```
Question 12hardmultiple choice
Read the full Strings explanation →

What is the value of matches?

Exhibit

Refer to the exhibit.

Configuration block:
```python
import re
pattern = r'\b[A-Z][a-z]*\b'
text = "Alice and Bob are friends."
matches = re.findall(pattern, text)
```
Question 13hardmultiple choice
Review the full routing breakdown →

You are a network engineer troubleshooting a script that processes router configuration files. The script reads a configuration line from a file: 'interface GigabitEthernet0/1

ip address 192.168.1.1 255.255.255.0
 no shutdown'. The script needs to extract the interface name and IP address. The current code uses string split operations but fails when the line has extra spaces or tabs. For example, when the line is 'interface   GigabitEthernet0/1', the split returns ['interface', '', '', 'GigabitEthernet0/1'] and the script fails. You need to modify the script to robustly extract the interface name and IP address regardless of whitespace. Which approach should you take?
Question 14mediummultiple choice
Read the full Strings explanation →

When processing a large text file, a developer notices that using str.replace() in a loop is slow. Which alternative is most efficient for multiple replacements?

Question 15hardmultiple choice
Read the full Strings explanation →

A programmer is writing a script to generate SQL queries safely. They need to escape single quotes in user-provided strings to prevent injection. Which approach is most robust?

Question 16mediummultiple choice
Read the full Strings explanation →

A developer wants to remove leading and trailing whitespace from a string. Which method should be used?

Question 17mediummulti select
Read the full Strings explanation →

Which TWO of the following methods return a boolean value?

Which TWO of the following are immutable in Python?

Question 19mediummultiple choice
Read the full Strings explanation →

Refer to the exhibit. What is the output of the code?

Exhibit

s = 'Python Programming'
print(s[7:])

Free account

Track your progress over time

Create a free account to save your results and see which topics improve across sessions.

Focused Strings sessions

Start a Strings only practice session

Every question in these sessions is drawn from the Strings domain — nothing else.

Related practice questions

Related PCAP topic practice pages

Move into related areas when this topic feels solid.

Frequently asked questions

What does the PCAP exam test about Strings?
Strings questions test whether you can apply the concept in context, not just recognise a definition.
How should I use these practice questions?
Select your answer before revealing the explanation. Then read why each option is right or wrong — this active recall approach builds retention far faster than re-reading notes.
Can I practise just Strings questions in a focused session?
Yes — the session launcher on this page draws every question from the Strings domain. Use a 10-question session first to gauge your baseline, then move to 20 or 30 once the weak spots are clear.
Where can I practise other PCAP topics?
Use the topic links above to move to related areas, or go back to the PCAP question bank to see all topics.
Are these real exam questions or dumps?
These are original practice questions written to test the same concepts the PCAP exam covers. They are not copied from any real exam or dump site.