Sign in
Home/Python Institute/Certified Associate in Python Programming (PCAP-31-03)/Free questions

Certified Associate in Python Programming (PCAP-31-03) — Free Practice Questions

10 free sample questions from a bank of 98, with the correct answers and explanations. No signup required — start practising right now.

1What is true about Python packages? (Choose two.)
  • a code designed to initialize a package’s state should be placed inside a file named init.py
  • a package’s contents can be stored and distributed as an mp3 file
  • __pycache__ is a folder that stores semi-compiled Python modules
  • the sys.path variable is a list of strings
Answer: C, D

The short version

This choose-two item is only satisfied by C plus D. Option C correctly describes __pycache__ as the cache for bytecode compiled modules, and option D correctly states that sys.path is a list of strings for module search. Option A misspells the package initializer and option B invokes an audio format with no packaging role.

Key concepts in this question

The item tests package initialization, bytecode caching, and import search. A package uses a dunder initializer module, imports compile sources to bytecode for speed, and the interpreter finds modules by scanning a mutable list of path strings. PCAP often tests exact filenames and container types, so precision matters more than general intuition here.

Why CD is correct

C is correct because CPython stores compiled .pyc files in __pycache__ beside the source, which matches the semi-compiled wording. D is correct because sys.path is documented as a list of strings and scripts routinely append entries or inspect it. No other pairing gives two factually accurate statements, so CD is the only sustainable answer.

Why the others are wrong

A is wrong because the initializer must carry double underscores on both sides, and plain init.py is not recognized as the package initializer. The vendor prose flags exactly this spelling fault. B is wrong because packages ship as source trees, zip archives, or wheels, never as mp3 audio, which the import system cannot read or execute.

PCAP-31-03 exam tip

Memorize dunder spellings character by character and learn the types of runtime objects like sys.path and sys.argv as lists. When one option has a filename typo and another states a plain type fact, reject the typo and keep the type fact, then verify the second choice the same way.

2What is true about the following snippet? (Choose two.)
Certified Associate in Python Programming (PCAP-31-03) question 2
  • the string what a pity will be seen
  • the string it's nice to see you will be seen
  • the code will raise an unhandled exception
  • the string I feel fine will be seen
Answer: B, D

The short version

BD — two branches print, no crash. The snippet reaches the print for I feel fine first and then the print for it is nice to see you, so both B and D appear and no unhandled exception escapes.

Key concepts in this question

  • Try and except flow: Python runs the try body in order until an exception occurs, then jumps to the first matching except block and continues after the whole construct.
  • Multiple prints as trace: each executed print leaves output, so the result is only the prints actually reached.
  • Exception matching: only an exception type named in an except clause is caught there, anything else propagates, while a fully covered exception never becomes unhandled.
  • Order of output: statements before the raise run, the raising line is skipped, and handlers run afterwards, so D can precede B.
  • Unhandled versus handled failure: a handled error resumes normally, while an unhandled one aborts with a traceback.

Why BD is correct

Both selected lines correspond to code paths that are actually executed in this run. The first visible line comes from the D branch that is reached before the exception transfer, and the second visible line comes from the B branch inside the handler that catches the raised error. Because the raised exception has a matching handler, execution resumes normally and the program terminates cleanly after printing B, which is exactly the BD behaviour noted in the vendor comment.

Why the others are wrong

  • A. The what a pity line sits on a path that is skipped once control transfers to the handler, so it never executes in this scenario.
  • C. The exception is caught by a matching handler and converted into normal B output, so the interpreter never reports an unhandled exception or traceback.

PCAP-31-03 exam tip

Remember prints as breadcrumbs: mark what runs before the raise, what the handler prints, and cross out everything that the jump skips.

3What is the expected behavior of the following code?
Certified Associate in Python Programming (PCAP-31-03) question 3
  • it outputs error
  • it outputs
  • the code is erroneous and it will not execute
  • it outputs list assignment index out of range
Answer: C

The short version

C — The snippet is erroneous and will not execute. The indexed store assignment targets an out-of-range or illegal slot before any handling, so the interpreter rejects the construct at run time. The settled key treats this as a broken program rather than a printable error string.

Key concepts in this question

  • List index assignment: writing to my_list at position three requires that slot to already exist.
  • Erroneous versus handled error: a structural fault that prevents execution differs from a caught exception that prints text.
  • Output options: error string versus traceback versus no execution each imply a different runtime path.
  • Vendor test note: community run shows the boundary write never yields a clean value output.

Why C is correct

The code attempts an indexed store beyond the current list length without append or extend, which is an illegal mutation for the shown literal. Python therefore cannot complete the statement as a normal value-producing step. The settled key classifies that as erroneous and non-executable rather than as a printed message branch.

Why the others are wrong

  • A. It outputs error overstates a generic print when the fault blocks normal completion.
  • B. It outputs alone claims a value print that the broken assignment never reaches.
  • D. List assignment index out of range describes a traceback text, not the settled erroneous-program verdict.

PCAP-31-03 exam tip

Out-of-range indexed store on a tiny literal means choose erroneous and will not execute.

4Which of the following expressions evaluate to True? (Choose two.)
  • ord("0") - ord("9") == 10
  • len("''") == 2
  • chr(ord('z') - 1) == 'y'
  • len(''1234'') == 4
Answer: C, D

The short version

CD — chr round-trip holds and four-char string has length four. The y from z-minus-one is True and the 1234 string length check is True, while the ord subtraction and the empty-quote length check are False.

Key concepts in this question

  • ord and chr as inverses: ord turns a single character into its Unicode code point and chr turns a code point back into a character, so round-trips preserve values.
  • ASCII ordering of digits: digits zero through nine occupy consecutive code points 48 through 57, so arithmetic on them yields small signed differences, not ten.
  • len counts characters: len reports the number of characters in a str object, with an empty string giving zero and a literal like 1234 giving four regardless of digit content.
  • Quoting versus content: quotes delimit a string but are not counted, so an empty pair contributes nothing while two single-quote characters inside a longer literal would count only if they are actual content.
  • Boolean comparison: each expression uses == to produce a real bool, so only exact numeric or character equality yields True.

Why CD is correct

C holds because ord of z is 122, minus one is 121, and chr of 121 is y, giving an exact match. D holds because the tested string consists of four digit characters, so len returns four and the equality with four is True. Together they are the only two True evaluations, which matches the settled CD key and the community vote after testing.

Why the others are wrong

  • A. ord of zero is 48 and ord of nine is 57, so the difference is minus nine, not ten, making the equality False.
  • B. The measured literal in this item is an empty string with length zero, so its comparison against two is False rather than True.

PCAP-31-03 exam tip

Memorize 48 for zero, 57 for nine, 122 for z, then do the subtraction on paper before trusting any True claim.

5What is the expected behavior of the following code? the_list = "alpha;beta;gamma".split(";") the_string = ''.join(the_list) print(the_string.isalpha())
  • it outputs True
  • it outputs False
  • it outputs nothing
  • it raises an exception
Answer: A

The short version

A — Join yields alphabets only, so True prints. Splitting alpha beta gamma on semicolons then joining with empty glue gives alphabetagamma. That string is all letters, so isalpha returns True.

Key concepts in this question

  • Split on delimiter: alpha beta gamma divided at semicolons produces three pure word parts.
  • Empty join: concatenating with empty string removes separators without adding new symbols.
  • Isalpha check: True only when every character is a letter with at least one character present.
  • Print of bool: outputs True with capital T, not nothing or an exception.

Why A is correct

The list becomes alpha plus beta plus gamma, and empty join fuses them into one continuous alphabetic run. No digits, spaces or punctuation survive to fail the test. Isalpha therefore evaluates to True and print shows True, matching the settled key.

Why the others are wrong

  • B. False would need a surviving separator or digit, but empty join leaves letters only.
  • C. Nothing would require no print call, yet the snippet explicitly prints the test result.
  • D. Exception would need a type or attribute fault, but split plus join plus isalpha are all valid here.

PCAP-31-03 exam tip

Split then empty join then isalpha on words alone always prints True.

6Which of the following invocations are valid? (Choose two.)
  • sort("python")
  • "python".find("")
  • "python".sort()
  • sorted("python")
Answer: B, D

The short version

BD — empty find works and sorted builds a list. The str find call with an empty pattern returns zero and the builtin sorted call accepts the string and returns a sorted list, while bare sort and str sort forms fail.

Key concepts in this question

  • Builtin sorted versus list sort: sorted is a builtin that accepts any iterable and returns a new list, while list sort is a method that sorts in place and returns None.
  • str has find but no sort: strings provide searching methods like find, but they are immutable and unordered, so they expose no sort method at all.
  • Empty substring rule: every string is considered to contain the empty string at position zero, so find with an empty pattern validly returns zero instead of raising.
  • Callable resolution: a bare name like sort must exist as a builtin or defined function, otherwise Python raises NameError at call time.
  • Attribute lookup: dotting a value with a missing method name raises AttributeError, which is how python dot sort fails.

Why BD is correct

B is valid because find is a genuine str method and an empty search string is explicitly allowed, returning zero for python. D is valid because sorted is a real builtin that iterates over the characters of python, orders them, and returns a new list such as hnopty. Both calls complete without any exception, so they are the two valid invocations.

Why the others are wrong

  • A. There is no builtin named sort for this purpose, so calling sort on a string raises NameError and is invalid.
  • C. The str type defines no method named sort, so attribute lookup fails with AttributeError and the call can never succeed.

PCAP-31-03 exam tip

If you see sort, ask sorted-or-method: sorted with an iterable is safe, dot-sort on a string is always wrong.

7Assuming that the snippet below has been executed successfully, which of the following expressions will evaluate to True? (Choose two.) string = 'python'[::2] string = string[-1] + string[-2]
  • len(string) == 3
  • string[0] == 'o'
  • string[0] == string[-1]
  • string is None
Answer: B

The short version

After both lines the variable holds ot, so only B is true. The slice with step two turns python into pto, then last plus middle characters build ot, whose first character is o and whose length is two rather than three. Banked AB mistakes the intermediate length for the final length.

Key concepts in this question

The item tests slicing with a step, negative indexing, and reassignment. Form s[::2] keeps every second character from zero, minus one is the last character, and assigning the same name twice discards the earlier value. PCAP chains these steps because learners remember the first result and forget the second line replaces it before len is checked.

Why B is correct

B says string zero equals o, true for final ot. Characters zero, two, and four of python are p, t, and o, giving pto. Then string minus one is o and string minus two is t, so their concat is ot. Index zero of ot is o, so the equality holds by direct trace with no outside dependence.

Why the others are wrong

A claims length three, true only for intermediate pto, while final ot has length two, so A confuses an earlier state with the tested state. C claims first equals last, but ot starts with o and ends with t, so it fails. D claims the name is None, yet it binds a str that supports indexing, so identity with None is false.

PCAP-31-03 exam tip

Rewrite the value after every assignment and evaluate options only against the last one. Write indices under the current string, with care for negative positions and steps. When a choose-two stem leaves only one survivor after tracing, select only that survivor instead of forcing a second letter.

8Which of the following statements are true? (Choose two.)
  • an escape sequence can be recognized by the / sign put in front of it
  • ASCII is a subset of UNICODE
  • II in ASCII stands for Internal Information
  • a code point is a number assigned to a given character
Answer: B, D

The short version

BD — ASCII lives inside Unicode and a code point is a number. Unicode preserves the first 128 ASCII assignments unchanged, and each character is identified by its numeric code point, while the other two statements misstate syntax and acronym meaning.

Key concepts in this question

  • ASCII versus Unicode: ASCII defines 128 characters with values 0 through 127, and Unicode deliberately starts with the same assignments so ASCII text remains valid Unicode.
  • Code point idea: a code point is simply the integer assigned to a character, such as 65 for Latin capital A or 122 for z, independent of how it is encoded in bytes.
  • Escape sequences: Python introduces escapes with a backslash, such as newline or tab, not with a forward slash, so slash-based claims are false.
  • Acronym expansion: ASCII stands for American Standard Code for Information Interchange, not for Internal Information, and the double I comes from Information Interchange.
  • Subset consequence: because the numbers match, ASCII bytes decode identically under UTF-8 and other Unicode encodings, which is why the subset claim matters.

Why BD is correct

B is correct because Unicode was designed as a superset that keeps ASCII values identical, so every ASCII text is automatically well-formed Unicode. D is correct by definition: standards assign each abstract character a unique non-negative integer called its code point, and Python exposes it through ord and chr. Those two definitional facts are exactly what the settled key asserts.

Why the others are wrong

  • A. Escape sequences use a backslash prefix, so a forward slash prefix never introduces an escape and the statement is false.
  • C. The letters I I in ASCII abbreviate Information Interchange, not Internal Information, so the expansion given is incorrect.

PCAP-31-03 exam tip

Link three facts: backslash escapes, 128 ASCII values preserved, code point equals ord number.

9What is the expected output of the following code? import sys import math b1 = type(dir(math)) is list b2 = type(sys.path) is list print(b1 and b2)
  • None
  • True
  • 0
  • False
Answer: B

The short version

B — both type checks are True, so True is printed. dir on the math module returns a list and sys path is a list, making b1 and b2 both True and their and-combination True.

Key concepts in this question

  • dir return type: dir always builds and returns a new sorted list of attribute-name strings for the given object, never a tuple or other sequence.
  • sys path type: sys path is the mutable list of directory strings that the import system searches, so it supports append and in-place edits.
  • Exact type test with is: comparing type result with is list checks identity against the list class, which succeeds only for genuine lists.
  • Boolean and semantics: and returns the first falsy operand or the last operand, so True and True evaluates to True rather than to one or zero.
  • print of bools: print renders True with a capital T, which distinguishes it from None, zero, or False outputs.

Why B is correct

b1 is True because dir of math produces a list of names like ceil and sqrt, whose type is exactly list. b2 is True because sys path is documented and implemented as a list of strings. True and True is True, so the final print emits True, matching the vendor run and the settled answer.

Why the others are wrong

  • A. The program prints the value of a boolean expression, never the None singleton, so None cannot be the output here.
  • C. Integer zero would require a falsy and-result or explicit zero value, but both operands are True, so zero is impossible.
  • D. False would require at least one operand to be non-list, yet both type tests succeed, ruling False out.

PCAP-31-03 exam tip

Memorize dir gives list and sys path is a list, then True and True can only print True.

10A property that stores information about a given class’s super-classes is named:
  • __bases__
  • __super__
  • __upper__
  • __ancestors__
Answer: A

The short version

A — direct bases live in dunder bases. The tuple stored in dunder bases lists the immediate superclasses named in the class header, which is the introspection hook the question asks for.

Key concepts in this question

  • Class creation: the class statement evaluates base expressions and stores them for later method-resolution use.
  • Dunder bases: every class exposes a dunder bases attribute that is a tuple of its direct parents, empty only for object itself.
  • Tuple snapshot: the value reflects inheritance declared at definition time and updates only if the class is rebuilt or its bases are reassigned.
  • Distractor names: Python defines no standard dunder super, dunder upper, or dunder ancestors for this purpose, so those names fail attribute lookup.
  • Related helpers: functions like issubclass and attributes like mro build on top of dunder bases but do not replace it as storage.

Why A is correct

Only dunder bases is the documented storage for parent-class references in CPython and in the language reference. Inspecting it shows exactly which classes were listed as bases, making it the property that stores information about super-classes. The other names have no such role, so A is uniquely correct.

Why the others are wrong

  • B. No standard dunder super attribute exists on classes, so lookup fails and it cannot report parents.
  • C. Dunder upper is not a defined class property and has no inheritance meaning.
  • D. Dunder ancestors is not part of the data model, so it never stores superclass information.

PCAP-31-03 exam tip

Think bases equals parents tuple: if you need immediate superclasses, read dunder bases.

Want the full bank of 98 questions for Certified Associate in Python Programming (PCAP-31-03)? See all practice exams.