Prepstellar

Python Fundamentals · Final test · 25 questions

Python Fundamentals final test: 25 free questions

Untimed here · timed and scored in the app

A free Python Fundamentals practice test with 25 questions drawn from the whole course. Answer at your pace and read why each option is right or wrong.

Swipe, scroll or use ← →
  1. Q1 / 25

    How can each subcommand carry the function that should handle it after parsing?

    1. APass the handler through every subcommand's `choices` list.
    2. BReplace `parse_args` with a separate parser for each call.
    3. CCall `set_defaults(func=handler)` on each subparser.
    4. DSet one global `type=handler` on the parent parser.
    Show the answer

    A subparser-specific default enters the chosen handler in the returned namespace, enabling direct dispatch after parsing.

    Next → 1 / 25
  2. Q2 / 25

    Which callable is equivalent to retrieving item one from an object?

    1. A`operator.attrgetter('1')`
    2. B`operator.itemgetter(1)`
    3. C`operator.contains(1)`
    4. D`operator.methodcaller('1')`
    Show the answer

    `itemgetter` builds an `__getitem__`-based accessor; attribute and method adapters perform different forms of lookup.

    Next → 2 / 25
  3. Q3 / 25

    What is the default discovery filename pattern in `unittest`?

    1. A`tests.pyc`
    2. B`spec-*.py`
    3. C`*_test.txt`
    4. D`test*.py`
    Show the answer

    The loader recursively considers importable modules whose filenames match `test*.py` unless a different pattern is supplied.

    Next → 3 / 25
  4. Q4 / 25

    Which naming style does the tutorial recommend for functions and methods?

    1. ALowercase words separated by underscores
    2. BUppercase words separated by tabs
    3. CUpperCamelCase words without separators
    4. DLowercase words separated by hyphens
    Show the answer

    Lowercase names with underscores distinguish functions and methods from the neighboring UpperCamelCase convention for classes.

    Next → 4 / 25
  5. Q5 / 25

    A child can emit unlimited output, must remain live for hours, and the parent must process records incrementally. Which choice follows from the documented tradeoff?

    1. AUse `Popen` with an incremental stream design instead of `communicate`.
    2. BUse `platform.platform` to select a larger pipe automatically.
    3. CUse `run(capture_output=True)` and retain everything until the long-lived child exits.
    4. DUse `communicate` because it never buffers output in memory.
    Show the answer

    `Popen` is the long-lived interface, while `communicate` buffers received data and is unsuitable for large or unbounded output.

    Next → 5 / 25
  6. Q6 / 25

    A command is run with `python -c command alpha beta`. What happens to `alpha` and `beta`?

    1. AThey remain in `sys.argv` for the command to handle.
    2. BThey are converted to numbers before the command runs.
    3. CThey replace `sys.argv[0]` with an empty string.
    4. DThey are consumed as additional interpreter options.
    Show the answer

    Values after the `-c` command are program arguments, while `sys.argv[0]` identifies the `-c` invocation.

    Next → 6 / 25
  7. Q7 / 25

    An aware meeting time must be displayed in another zone while preserving the exact UTC moment. Its wall-clock fields may change to reflect the destination. Which operation meets both requirements?

    1. AFormat the original value and parse the same fields without an offset.
    2. BCall `meeting.replace(tzinfo=None)` and compare the resulting fields.
    3. CCall `meeting.replace(tzinfo=destination_zone)`.
    4. DCall `meeting.astimezone(destination_zone)` and use its adjusted fields.
    Show the answer

    `astimezone` adjusts date and time fields so that the destination representation denotes the same UTC instant.

    Next → 7 / 25
  8. Q8 / 25

    What is a Python module in this introductory model?

    1. AAn operating system
    2. BA reusable unit of Python program code
    3. CA name reserved exclusively for third-party frameworks
    4. DA replacement syntax that the interpreter cannot execute
    Show the answer

    Modules split programs into reusable code that other Python programs can use.

    Next → 8 / 25
  9. Q9 / 25

    A generator-based context manager must release a resource on every exit path, log failures from the managed block, and still let those failures propagate. Which structure satisfies all requirements?

    1. AAcquire, then `try: yield resource`, log and re-raise in `except`, and release in `finally`
    2. BAcquire and release before `yield resource`, then re-raise every normal completion
    3. CAcquire, then `yield resource`, and release only after the yield without `finally`
    4. DAcquire, catch and log around `yield resource`, omit re-raising the failure, then release in `finally`
    Show the answer

    The `finally` suite guarantees release, while re-raising after logging prevents the generator manager from reporting that the block's failure was handled.

    Next → 9 / 25
  10. Q10 / 25

    What happens when execution enters a class definition?

    1. AA new namespace becomes the local scope for the class body.
    2. BA new instance becomes the global scope for the module.
    3. CThe class body runs inside each future instance namespace.
    4. DThe surrounding namespace is copied into a new instance.
    Show the answer

    The class suite executes once in a fresh namespace; after normal completion, that namespace is wrapped in a class object.

    Next → 10 / 25
  11. Halfway, at your pace

    In the app the mock exam is timed and scored like the real thing.

  12. Q11 / 25

    In `[[row[i] for row in matrix] for i in range(4)]`, what does one outer iteration build?

    1. AOne original matrix row with its position `i` removed
    2. BOne complete list containing position `i` from every row
    3. COne dictionary mapping every row to its position `i`
    4. DOne flat list containing every position from every row
    Show the answer

    For each outer column index, the inner comprehension visits every row and collects the item at that index.

    Next → 11 / 25
  13. Q12 / 25

    How can a user install the packages recorded in `requirements.txt`?

    1. ARun `python -m pip install -r requirements.txt`.
    2. BRun `deactivate -r requirements.txt`.
    3. CRun `python -m pip show -r requirements.txt`.
    4. DRun `python -m venv freeze requirements.txt`.
    Show the answer

    The `-r` option gives `pip install` a requirements file whose entries use the format produced by `freeze`.

    Next → 12 / 25
  14. Q13 / 25

    Which documented use passes a lambda as a callable argument?

    1. ASupplying a docstring to `*args`
    2. BSupplying a sorting key to `list.sort`
    3. CSupplying the slash marker to `range`
    4. DSupplying keyword names to a tuple
    Show the answer

    A sorting key is a function object, so a single-expression lambda can fill that callable role.

    Next → 13 / 25
  15. Q14 / 25

    What does `Thread.start()` do?

    1. ARuns the target synchronously inside the original caller thread
    2. BWaits until the target has already terminated
    3. CInvokes the target in a separate thread of control
    4. DCreates a separate process with isolated memory
    Show the answer

    Starting a thread schedules its `run` method in another thread; calling `run` directly does not provide that lifecycle.

    Next → 14 / 25
  16. Q15 / 25

    When does a `finally` clause run?

    1. AIt requires an `except` clause to handle a failure before cleanup can begin.
    2. BIt begins after an unmatched exception has already stopped execution.
    3. CIt is skipped whenever the associated `try` clause raises an exception.
    4. DWhether the associated `try` clause succeeds or raises an exception
    Show the answer

    `finally` supplies an all-circumstances cleanup path and runs as the last task before the `try` statement completes.

    Next → 15 / 25
  17. Q16 / 25

    How does Python expose a script name and its subsequent arguments to a program?

    1. AAs strings in the list `sys.path`.
    2. BAs strings in the list `sys.argv`.
    3. CAs variables created in the program's global scope.
    4. DAs numbers in the tuple `sys.argv`.
    Show the answer

    Importing `sys` exposes `sys.argv`, whose string elements describe the invocation rather than the module search path.

    Next → 16 / 25
  18. Q17 / 25

    Which function computes the middle-value measure that is less affected by an extreme outlier than the arithmetic mean?

    1. A`statistics.fmean`
    2. B`statistics.mean` over all values
    3. C`statistics.mode`
    4. D`statistics.median`
    Show the answer

    The median is based on the middle position and is more robust to extreme magnitudes than either arithmetic-mean function.

    Next → 17 / 25
  19. Q18 / 25

    Which resource is distributed with Python?

    1. AEvery community package
    2. BAll optional system components on every Unix installation
    3. CEvery application framework listed on the Package Index
    4. DThe Python standard library
    Show the answer

    The standard library accompanies Python and provides a broad set of standardized facilities.

    Next → 18 / 25
  20. Q19 / 25

    What happens to a file managed by `with` when its suite raises an exception?

    1. AThe file closes only if the exception is caught inside the suite
    2. BThe file is closed as the managed suite exits
    3. CThe file stays open until another `with` statement uses it
    4. DThe file is reopened automatically before the exception propagates
    Show the answer

    The file's predefined cleanup runs when control leaves the managed suite, whether completion is normal or caused by a failure.

    Next → 19 / 25
  21. Q20 / 25

    Which statement correctly contrasts updating a list with concatenating an immutable sequence?

    1. AThe list update creates a new list; concatenation changes the immutable object in place.
    2. BBoth operations change their existing sequence objects in place.
    3. CThe list can change in place; concatenation creates a new immutable sequence object.
    4. DNeither operation can produce an updated sequence value.
    Show the answer

    Lists support in-place mutation, while an immutable sequence cannot be altered and concatenation therefore yields another object.

    Next → 20 / 25
  22. Q21 / 25

    What does the chained comparison `a < b == c` require?

    1. ABoth `a < c` and `b == c` must hold.
    2. BEither `a < b` or `a == c` must hold.
    3. CBoth `a < b` and `b == c` must hold.
    4. DOnly `a < b` is tested; `== c` is ignored.
    Show the answer

    A comparison chain links adjacent operands, so the middle value `b` participates in both required comparisons.

    Next → 21 / 25
  23. Q22 / 25

    What value does a module receive in `__name__` when Python runs it as the main file?

    1. AThe string `"__main__"`
    2. BThe module's filename with `.py`
    3. CThe directory containing the script
    4. DThe string `"__import__"`
    Show the answer

    Main-file execution uses a special name that a module can test to separate script behavior from imported behavior.

    Next → 22 / 25
  24. Q23 / 25

    What does `functools.partial` create?

    1. AA dispatcher selected by the last argument's type
    2. BA callable with selected arguments already supplied
    3. CAn unbounded cache that stores every prior return value for reuse
    4. DA class with every comparison method generated
    Show the answer

    Partial application narrows a callable's remaining input surface; caching, ordering, and dispatch are separate adapters.

    Next → 23 / 25
  25. Q24 / 25

    A notebook already owns an event loop, and a cell needs to run a coroutine without creating a nested application loop. What should the code do?

    1. AStart a process pool solely to obtain `get_running_loop`.
    2. BCall `asyncio.run` inside the running loop every time.
    3. CCreate a `threading.Lock` and use it as the event loop.
    4. DAwait the coroutine through the notebook's active-loop integration.
    Show the answer

    `asyncio.run` is the normal script boundary, while environments that own a loop expose their own direct-await or integration model.

    Next → 24 / 25
  26. Q25 / 25

    What happens when an exception from a `try` clause matches none of its `except` clauses?

    1. AThe first `except` clause runs even though its type does not match.
    2. BIt propagates to an outer `try`, or becomes unhandled if no handler exists.
    3. CEvery `except` clause runs once before the exception can propagate.
    4. DPython skips the failure and continues after the statement automatically without reporting it.
    Show the answer

    Selection is type-based: only a matching handler runs, while an unrelated failure remains available to outer handling.

    Next → 25 / 25
  27. That’s the whole mock exam

    Every question you miss comes back exactly when you’re about to forget it.

How to use this mock exam

Sit all 25 questions in one go: the mix covers every domain in the same proportion as the exam, so a low score points at the domain you skipped rather than at bad luck.

Read the explanation under every question, including the ones you got right — the reason an option is wrong is usually the thing being tested.

Then retake it in the app, where the mock exam is timed and scored and the questions you miss come back on a schedule.

The whole course, on your phone

Lessons you can read, audio you can listen to on the way to work, and practice that remembers what you got wrong.