What the PCAP exam covers
- Modules and Packages109 questions
- Exceptions123 questions
- Strings157 questions
- Object-Oriented Programming246 questions
- Miscellaneous192 questions
Free PCAP practice test questions
A sample of 10 questions with answers and explanations. Sign up free to practice all 827.
-
Which import statement makes the name sqrt usable WITHOUT any module prefix, so that sqrt(9) works directly?
- Afrom math import sqrtCorrect
- Bimport math
- Cimport math.sqrt
- Dimport sqrt from math
✓ Correct answer: AThe from-import form 'from math import sqrt' binds sqrt directly in the current namespace, so you call it as sqrt(9) with no prefix.
Why the other options are wrong- Bimport math binds only the name math, so you would have to write math.sqrt(9).
- Cimport math.sqrt is invalid because sqrt is a function, not an importable submodule of math.
- D'import sqrt from math' is not valid Python; the correct order is 'from math import sqrt'.
-
A module defines both public and internal names: def process(): return _clean() def _clean(): return "ok" After 'import mod', which call is considered the intended public entry point?
- Amod.process()Correct
- Bmod._clean()
- CNeither, both are private
- DBoth are equally public by convention
✓ Correct answer: Aprocess has no leading underscore, marking it public. _clean begins with an underscore, signalling an internal helper that callers should not rely on directly.
Why the other options are wrong- B_clean's leading underscore marks it as internal, not the public interface.
- Cprocess has no underscore, so it is public, not private.
- DThe underscore distinguishes them; _clean is conventionally private, process is public.
-
What is the output? try: raise ValueError except ValueError as e: print(repr(e.args))
- A()Correct
- BNone
- C('',)
- DValueError
✓ Correct answer: Araise ValueError raises the class, which Python instantiates with no arguments, equivalent to raise ValueError(). So e.args is the empty tuple ().
Why the other options are wrong- Bargs is always a tuple, never None.
- CNo empty-string argument is added; args is simply empty.
- De.args is printed, which is an empty tuple, not the class name.
-
What is the output of the following code? print("[" + "hi".rjust(5, ".") + "]")
- A[...hi]Correct
- B[hi...]
- C[.hi..]
- D[ hi]
✓ Correct answer: Arjust(5, ".") right-justifies "hi" in a field of width 5, padding on the left with dots until the width is reached.
Why the other options are wrong- BThat is ljust, which pads on the right.
- Crjust puts all the padding on the left, not split around the text.
- DThe explicit fill character is ".", not a space.
-
What is the output of the following code? s = 'abcdef' print(s[5:0:-1])
- AfedcbCorrect
- Bfedcba
- Cedcba
- Dfedc
✓ Correct answer: AWith start 5, stop 0, and step -1, the slice walks backward from index 5 down to but not including index 0. That covers indices 5, 4, 3, 2, 1: 'f', 'e', 'd', 'c', 'b', giving 'fedcb'. The character at index 0 ('a') is excluded because stop is exclusive.
Why the other options are wrong- B'fedcba' would include index 0, but stop=0 is exclusive, so 'a' is left off. A full reversal needs s[::-1].
- C'edcba' would start at index 4; here the start is index 5 ('f').
- D'fedc' stops too early; the slice continues down to index 1 ('b').
-
Which statement about the name self is correct?
- Aself is a reserved keyword and using another name is a SyntaxError.
- Bself is a built-in function that returns the current instance object.
- Cself is only a naming convention, not a keyword, for the first parameter.Correct
- Dself is a keyword only inside classes and ordinary functions may reuse it.
✓ Correct answer: CThe first parameter of an instance method could legally be named anything; Python passes the instance regardless of the name. self is a universally followed convention, not a reserved word, so no SyntaxError occurs if you rename it. Using another name is simply discouraged.
Why the other options are wrong- ARenaming the first parameter is legal, not a SyntaxError.
- Bself is a parameter name, not a built-in function.
- Dself is never a keyword, inside or outside classes.
-
What is the output of the following code? print(isinstance(True, int))
- ATrueCorrect
- BFalse
- CNone
- DTypeError
✓ Correct answer: AIn Python, bool is a subclass of int, so a boolean value is also an instance of int. isinstance(True, int) therefore returns True.
Why the other options are wrong- Bbool derives from int, so True is an int instance as well.
- Cisinstance returns a bool, not None.
- Dint is a valid class argument, so there is no error.
-
What is the output of the following code? def gen(): x = 0 while True: x += 1 yield x g = gen() print(next(g), next(g), next(g))
- A1 2 3Correct
- B0 1 2
- C1 1 1
- D3 3 3
✓ Correct answer: AThe generator resumes where it left off each time, keeping the value of x between calls. Successive next() calls yield 1, 2, then 3.
Why the other options are wrong- Bx is incremented before the first yield, so the first value is 1, not 0.
- CState is preserved between resumes, so x keeps growing.
- DEach next() yields the current value as x increases; they are not all 3.
-
What is the output of the following code? nums = [3, 1, 4, 1, 5, 9, 2] top2 = sorted(nums, reverse=True)[:2] print(top2)
- A[9, 5]Correct
- B[3, 1]
- C[1, 1]
- D[9, 5, 4]
✓ Correct answer: Asorted(nums, reverse=True) gives [9, 5, 4, 3, 2, 1, 1], and slicing [:2] takes the two largest, 9 and 5.
Why the other options are wrong- BThese are the first two original elements, not the two largest after sorting.
- C1 is the smallest value; the slice takes the largest two from the descending sort.
- DThe slice [:2] returns only two elements, not three.
-
What does calendar.isleap(1900) return?
- ATrue
- BFalseCorrect
- CNone
- DIt raises ValueError
✓ Correct answer: B1900 is divisible by 100 but not by 400, so it is not a leap year and calendar.isleap returns False.
Why the other options are wrong- AA century year must also be divisible by 400 to be a leap year; 1900 is not, so it is False.
- Cisleap returns a Boolean, never None.
- Disleap simply returns a Boolean and does not raise for a valid year.
Who this PCAP practice exam is for
This practice set is for anyone preparing for the PCAP: Certified Associate Python Programmer exam at the intermediate level - from first-time candidates building a foundation to experienced Python practitioners doing a final review before test day. If you learn best by working through realistic questions and reading why each answer is right or wrong, it is built for you.
How to use this PCAP practice exam
- Start with the free sample questions above to gauge your current baseline.
- Read the full explanation on every question, including why each wrong option is wrong.
- Track your weak domains and focus your study where you are losing the most marks.
- Once you are scoring consistently well, take a timed, full-length mock exam.
- Use your readiness score to decide when you are ready to book the real PCAP exam.
Related Python resources
- PCAP study guideKey concepts
- Python practice examsAll Python
- Certification pathWhere this fits
- PCEP vs PCAPComparison
- Certification exam guides & tipsBlog
- Plans & pricingFree & paid
- Hands-on pcap labsLearn
- PCAP cheat sheetCheat sheet
- How these questions are written and reviewedMethodology
- Report a problem with a questionCorrections
- PCEP practice examRelated
- Python Automation for IT practice examRelated
PCAP practice exam FAQ
How many questions are in the PCAP practice exam on CertGrid?
CertGrid has 827 practice questions for PCAP: Certified Associate Python Programmer, covering 5 exam domains. The real PCAP exam is 40 qs in 65 min. CertGrid's timed mock is a fixed 40 questions.
What is the passing score for PCAP?
The PCAP exam passing score is 70%, and you have about 65 min to complete it. CertGrid scores your practice attempts the same way so you know when you are ready.
Are these official PCAP exam questions?
No. CertGrid is an independent practice platform. We do not provide real or leaked exam questions. Our questions are original and designed to help you practice the concepts, scenarios, and difficulty style of the PCAP: Certified Associate Python Programmer exam.
Is there a free PCAP practice test?
Yes. You can take a free PCAP: Certified Associate Python Programmer practice test straight away: a fixed set of 20 practice questions for this exam, retryable as often as you like, with no credit card required. You get readiness scoring and a weak-domain breakdown on those questions. Paid plans unlock the full 827-question bank, timed mock exams and full-bank domain analytics.
What CertGrid is (and is not)
CertGrid is an independent IT certification practice platform for Azure, AWS, Google, Cisco, Security, Linux, Kubernetes, Terraform, and other certification tracks. It provides objective-mapped practice questions, readiness scoring, weak-domain drills, and explanations to help learners understand what to study next.
Independent & original. CertGrid is not affiliated with or endorsed by Microsoft, AWS, Google, Cisco, CompTIA, the Linux Foundation, HashiCorp, or other certification vendors. Questions are original practice items designed to mirror certification concepts and exam style. CertGrid does not provide official exam questions or braindumps.