10 free sample questions from a bank of 98, with the correct answers and explanations. No signup required — start practising right now.
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.
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.
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.
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.
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.
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.
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.
Remember prints as breadcrumbs: mark what runs before the raise, what the handler prints, and cross out everything that the jump skips.
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.
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.
Out-of-range indexed store on a tiny literal means choose erroneous and will not execute.
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.
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.
Memorize 48 for zero, 57 for nine, 122 for z, then do the subtraction on paper before trusting any True claim.
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.
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.
Split then empty join then isalpha on words alone always prints True.
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.
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.
If you see sort, ask sorted-or-method: sorted with an iterable is safe, dot-sort on a string is always wrong.
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.
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.
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.
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.
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.
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.
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.
Link three facts: backslash escapes, 128 ASCII values preserved, code point equals ord number.
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.
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.
Memorize dir gives list and sys path is a list, then True and True can only print True.
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.
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.
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.