Courseiva

PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions

A developer writes a function `def log_event(message, level='INFO'):` that appends a formatted string to a list. The developer calls `log_event('disk full')` and then `log_event('retrying', level='WARN')`. What is the result of these two calls?

⚠ Common exam trap

The trap here is believing that passing a keyword argument in one call rewrites the function's default, when defaults are fixed at definition time and merely overridden per call.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

The first call uses 'INFO' for level and the second uses 'WARN', because the default applies only when the argument is omitted.

Default arguments make a parameter optional and are bound only when the caller omits that argument. An explicit keyword argument replaces the default for that single call without changing the function's definition, so the first invocation logs at INFO and the second at WARN. Calls that mix positional and keyword arguments are valid when each parameter is filled once.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    The first call uses 'INFO' for level and the second uses 'WARN', because the default applies only when the argument is omitted.

    Why this is correct

    Default parameter values are used only when the caller does not supply that argument. The first call omits level, so the default 'INFO' is bound; the second call passes level explicitly by keyword, which overrides the default with 'WARN'. Both calls succeed and produce the intended log entries for the developer.

  • ✗

    The first call raises a TypeError because a function with a default parameter must always receive that argument explicitly.

    Why it's wrong here

    A parameter with a default is optional by definition; omitting it is exactly the situation the default exists to handle. The call `log_event('disk full')` binds message to the string and level to 'INFO'. No error occurs, and the function can be invoked with a single argument whenever the default severity is acceptable.

  • ✗

    The second call raises a TypeError because positional and keyword arguments cannot be mixed in the same call.

    Why it's wrong here

    Python allows mixing positional and keyword arguments as long as no argument receives a value twice. The call `log_event('retrying', level='WARN')` supplies message positionally and level by keyword, which is perfectly valid. A TypeError would arise only if message were also passed by keyword after being filled positionally.

  • ✗

    Both calls use 'WARN', because the second call permanently changes the default for later invocations.

    Why it's wrong here

    Assigning an argument in one call has no effect on the function's default value; defaults are evaluated once at function definition time and remain fixed unless the function object itself is modified. The first call therefore still receives 'INFO'. Only mutable default objects can be accidentally shared, and rebinding a parameter name is not that case.

About these practice questions

One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Python Institute exam blueprint

This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.