Courseiva
Knowledge + Practice
CertificationsVendorsCareer RoadmapsLabs & ToolsStudy GuidesGlossaryPractice Questions
C
Courseiva

Free IT certification practice questions with explained answers for CCNA, CompTIA, AWS, Azure, Google Cloud, and more.

Certification Practice Questions

CCNA practice questionsSecurity+ SY0-701 practice questionsAWS SAA-C03 practice questionsAZ-104 practice questionsAZ-900 practice questionsCLF-C02 practice questionsA+ Core 1 practice questionsGoogle Cloud ACE practice questionsCySA+ CS0-003 practice questionsNetwork+ N10-009 practice questions
View all certifications →

Product

CertificationsCertification PathsExam TopicsPractice TestsExam Dumps vs Practice TestsStudy HubComparisons

Company

AboutContactEditorial PolicyQuestion Writing PolicyTrust Center

Legal

Privacy PolicyTerms of Service

Courseiva is a free IT certification practice platform offering original exam-style practice questions, detailed explanations, topic-based practice, mock exams, readiness tracking, and study analytics for Cisco, CompTIA, Microsoft, AWS, and other technology certifications.

© 2026 Courseiva. Courseiva is operated by JTNetSolutions Ltd. All rights reserved.

Courseiva is an independent certification practice platform and is not affiliated with, endorsed by, or sponsored by Cisco, Microsoft, AWS, CompTIA, Google, ISC2, ISACA, or any other certification vendor. Vendor names and certification marks are used only to identify the exams learners are preparing for.

HomeCertificationsPCAPTopicsStrings
Free · No Signup RequiredPython Institute · PCAP

PCAP Strings Practice Questions

19+ practice questions focused on Strings — one of the most tested topics on the Certified Associate Python Programmer PCAP exam. Each question includes a detailed explanation so you learn why the right answer is correct.

Start Strings Practice

Exam Domains

Modules and PackagesStringsObject-Oriented ProgrammingExceptions and File I/OAll domains →

Study Tools

Practice TestMock ExamFlashcardsAll Topics

Sample Strings Questions

Practice all 19+ →
1.

A developer needs to count the number of occurrences of the substring 'is' in the string 'This is a test. Is this a test?'. Which code correctly performs the count?

A.'This is a test. Is this a test?'.split().count('is')
B.'This is a test. Is this a test?'.count('is')
C.'This is a test. Is this a test?'.index('is')
D.'This is a test. Is this a test?'.find('is')

Explanation: Option B is correct because Python's string method `count(substring)` returns the number of non-overlapping occurrences of the substring in the string. In 'This is a test. Is this a test?', 'is' appears twice (in 'This' and 'is'), and the method counts them correctly, ignoring case sensitivity (the capitalized 'Is' is not counted).

2.

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

A.def is_pal(s): s = s.lower(); return s == ''.join(reversed(s))
B.def is_pal(s): s = ''.join(c for c in s if c.isalnum()).lower(); return s == s[::-1]
C.def is_pal(s): return s == s[::-1]
D.def is_pal(s): s = s.lower(); return s == s[::-1]

Explanation: Option B is correct because it first filters the string to keep only alphanumeric characters using `c.isalnum()`, converts the result to lowercase with `.lower()`, and then compares the string to its reverse using slicing `s[::-1]`. This correctly handles case insensitivity and ignores non-alphanumeric characters, which is the standard approach for palindrome checking in Python.

3.

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?

A.r'[0-9]+\. [0-9]+\.[0-9]+\.[0-9]+'
B.r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
C.r'(?:[0-9]{1,3}\.){3}[0-9]{1,3}'
D.r'\d+\.\d+\.\d+\.\d+'

Explanation: Option C is correct because it uses a non-capturing group `(?:...)` to repeat the pattern `[0-9]{1,3}\.` exactly three times, followed by a final octet `[0-9]{1,3}`. This matches the dotted-decimal structure of an IPv4 address (four octets, each 1–3 digits, separated by dots) without introducing extra spaces or overly permissive digit counts, and it avoids capturing unnecessary groups.

4.

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

A.str.isdigit()
B.str.isalnum()
C.str.isdecimal()
D.str.isnumeric()

Explanation: The `str.isdigit()` method returns `True` if all characters in the string are digits (0-9) and the string is non-empty. This is the most direct and commonly used method for checking numeric-only strings in Python, as it specifically tests for digit characters without including other numeric forms like fractions or Roman numerals.

5.

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?

A.re.sub(r'\bcat\b', 'dog', s)
B.s.replace('cat', 'dog')
C.re.sub('cat', 'dog', s)
D.s.replace('cat', 'dog', 1)

Explanation: Option A uses the `re.sub()` function with the regex pattern `r'\bcat\b'`, where `\b` denotes a word boundary. This ensures that only the whole word 'cat' is matched and replaced with 'dog', ignoring cases where 'cat' appears as part of a larger word like 'category'. The `r` prefix makes it a raw string, preventing escape sequence issues.

+14 more Strings questions available

Practice all Strings questions

How to master Strings for PCAP

1. Baseline your knowledge

Start with 10 questions to gauge your current understanding of Strings. This tells you whether you need a concept refresher or just practice.

2. Review every explanation

For each question — right or wrong — read the full explanation. Understanding why an answer is correct is more valuable than knowing the answer itself.

3. Focus on exam traps

Strings questions on the PCAP frequently use trap wording. Look for subtle differences in answers that test your precision, not just general knowledge.

4. Reach 80% consistently

Do repeated sessions until you score 80%+ three times in a row. Then move to mixed-mode practice to test cross-topic recall under realistic conditions.

Frequently asked questions

How many PCAP Strings questions are on the real exam?

The exact number varies per candidate. Strings is tested as part of the Certified Associate Python Programmer PCAP blueprint. Practicing with targeted Strings questions ensures you can handle any format or difficulty that appears.

Are these PCAP Strings practice questions free?

Yes. Courseiva provides free PCAP practice questions across all exam topics and domains. The platform includes topic-based practice, mock exams, missed-question review, bookmarked questions, and readiness tracking — no account required.

Is Strings one of the harder PCAP topics?

Difficulty is subjective, but Strings is a high-priority exam concept tested in multiple ways — direct recall, scenario analysis, and command-output interpretation. Consistent practice is the best way to build confidence.

Ready to practice?

Launch a full Strings practice session with instant scoring and detailed explanations.

Start Strings Practice →

Topic Info

Topic

Strings

Exam

PCAP

Questions available

19+