Courseiva
Exceptions and File I/O →mediumMultiple Choice

PCAP Default return value Practice Question

Exhibit

Refer to the exhibit.

Exhibit:
    def parse_value(data):
        try:
            value = int(data)
            return value
        except ValueError:
            return None
        except TypeError:
            return None
        except:
            return -1
    
    result = parse_value('abc')
    print(result)

What will be printed?

⚠ Common exam trap

Candidates often mistake the absence of a return statement for an implicit return of 0 or -1, or think an exception is raised. However, Python functions default to returning None, and printing that yields 'None'.

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

✓

None

None. This question likely tests that Python functions return None by default when no explicit return statement is present, and printing that value yields None. Therefore, option D is correct.

Answer analysis

Option-by-option breakdown

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

  • ✗

    -1

    Why it's wrong here

    -1 would be assigned only if the exception were not caught by a type-specific handler and instead fell through to a bare except: or other fallback logic that assigns -1. Here, the raised exception is a ValueError, which is exactly the type matched by the `except ValueError` block, so the control flow jumps to that handler and the assignment of -1 is never executed.

  • ✗

    0

    Why it's wrong here

    The value 0 would require the conversion `int("abc")` to somehow produce a numeric zero, but `int()` raises a ValueError when given a non-numeric string rather than silently defaulting to 0. Since the exception is caught by the `except ValueError` handler, the variable that would later be printed is never set to 0; the handler assigns its own value instead.

  • ✗

    An exception is raised.

    Why it's wrong here

    An exception being raised implies that the ValueError propagates uncaught and terminates the program, but that is not the case here. The `try`/`except ValueError` structure explicitly intercepts the exception at the point it is raised, so the normal flow of execution resumes inside the handler; no exception escapes to the outer scope, and the program prints normally.

  • ✓

    None

    Why this is correct

    The correct output is None because `int("abc")` raises a ValueError, which is caught by the matching `except ValueError` block. That handler assigns the result variable to None, and when the code later prints that variable, Python displays the string representation of None (i.e., "None").

About these practice questions

One of 421 original PCAP 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 by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCAP 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 PCAP exam.