What the PCAP exam covers
- Modules and Packages107 questions
- Exceptions118 questions
- Strings153 questions
- Object-Oriented Programming235 questions
- Miscellaneous186 questions
Free PCAP practice test questions
A sample of 10 questions with answers and explanations. A free account includes a fixed set of 20 practice questions for this exam, retryable anytime. Paid access unlocks the full 799-question bank.
-
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'.
-
What does platform.system() return?
- AThe operating system name, such as 'Linux', 'Windows', or 'Darwin'.Correct
- BThe Python interpreter version, such as '3.11.4'.
- CThe machine hardware type, such as 'x86_64'.
- DThe network hostname of the current machine.
✓ Correct answer: Aplatform.system() returns the OS/system name as a string, for example 'Linux', 'Windows', or 'Darwin' on macOS. It returns an empty string if the value cannot be determined. Other details come from separate calls in the platform module.
Why the other options are wrong- BThe interpreter version is returned by platform.python_version(), not system().
- CThe machine hardware type comes from platform.machine(), such as 'x86_64'.
- DThe hostname comes from platform.node() or socket.gethostname(), not system().
-
What is the output? ```python class E(Exception): pass print(repr(str(E()))) ```
- A''Correct
- B'None'
- C'E'
- D'()'
✓ Correct answer: AAn exception created with no arguments has an empty string form, so str(E()) is '' and its repr is ''.
Why the other options are wrong- Bstr() of an argument-less exception is empty, not the string 'None'.
- CThe class name is not part of str(); it is empty.
- Dstr() is an empty string, not the repr of an empty tuple.
-
What is the output of the following code? ```python print("x" + str(3.5)) ```
- Ax3.5Correct
- Bx3
- CTypeError
- D3.5x
✓ Correct answer: Astr(3.5) converts the float into its text form '3.5'. The + operator between two strings performs concatenation, joining the operands left to right, so 'x' followed by '3.5' produces 'x3.5'. No numeric addition happens because both sides are strings.
Why the other options are wrong- Bstr() renders the whole float value including the fractional part, giving '3.5'; it never truncates to the integer text '3'.
- Cstr(3.5) already produced a string, so both operands of + are strings and concatenation succeeds; a TypeError would only occur if you tried 'x' + 3.5 with the raw float.
- DString concatenation preserves operand order, and 'x' is the left operand, so it leads the result rather than trailing after '3.5'.
-
How does a class variable behave with respect to the instances of the class?
- AEach instance receives its own independent copy at creation.
- BIt cannot be read through an instance, only through the class.
- CIt is shared by all instances until one shadows it with its own attribute.Correct
- DReassigning it through any instance changes the shared value for every instance.
✓ Correct answer: CAttribute lookup checks the instance first and then falls back to the class, so until an instance assigns its own attribute of that name, every instance reads the single shared class variable. Assigning through an instance, such as self.x = 5, creates an instance attribute that shadows the class variable for that object only. The class variable itself is unchanged.
Why the other options are wrong- AInstances do not get separate copies; they share one class variable until shadowed.
- BA class variable can be read through an instance via normal attribute lookup.
- DAssigning through an instance creates an instance attribute; it does not change the shared value for others.
-
What is the output of the following code? ```python class R: __total = 100 print(R._R__total) ```
- A100Correct
- BAttributeError
- CNone
- D0
✓ Correct answer: AThe class-level __total is mangled to _R__total. Accessing that mangled name on the class from outside succeeds and returns 100.
Why the other options are wrong- BThe class attribute is stored under _R__total, so this access succeeds without an AttributeError.
- CThe attribute was assigned 100, not left as None.
- D_R__total holds 100, so 100 is printed, not 0.
-
What is the output of the following code? ```python class A: pass class B: pass print(isinstance(A(), B)) ```
- AFalseCorrect
- BTrue
- CNone
- DTypeError
✓ Correct answer: AThe two classes are unrelated with no inheritance link, so an A instance is not an instance of B. isinstance returns False.
Why the other options are wrong- BThere is no inheritance link between the two classes, so the instance does not match B.
- Cisinstance returns a bool, not None.
- DB is a valid class argument, so the call runs without error.
-
What is the output of the following code? ```python g = (x for x in range(3)) a, b, c = g print(a, b, c) ```
- A0 1 2Correct
- B0 0 0
- CTypeError is raised
- DValueError is raised
✓ Correct answer: AIterable unpacking drives the generator, drawing exactly three values 0, 1, 2 into a, b, c.
Why the other options are wrong- BEach name gets a distinct value from the generator, not the same value.
- CGenerators are iterable, so they can be unpacked; no error occurs.
- DThere are exactly three values for three targets, so no ValueError is raised.
-
What does open('new.txt', 'x') do when 'new.txt' does not yet exist?
- AIt creates the file and opens it for writingCorrect
- BIt raises FileNotFoundError
- CIt opens the existing file for reading
- DIt returns None without creating anything
✓ Correct answer: AExclusive creation mode 'x' creates the file and opens it for writing when the file is absent; it raises only when the file already exists.
Why the other options are wrong- BFileNotFoundError applies to reading a missing file, not to creating one with 'x'.
- C'x' opens for writing a new file, not reading an existing one.
- Dopen() returns a file object, never None, on success.
-
In Python, what is the usual role of datetime.date?
- ACreates or represents a calendar date.Correct
- BRepresents a date together with a time of day.
- CRepresents a duration between two points in time.
- DReturns the current time as a float timestamp.
✓ Correct answer: Adatetime is part of the Python module ecosystem. The member date provides a focused utility rather than changing language syntax or exception behavior.
Why the other options are wrong- BThat describes datetime.datetime, which carries both the date and the time.
- CThat describes datetime.timedelta, which models a span rather than a point.
- DThat describes time.time from the time module, not a datetime class.
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 799 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 799-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.