Courseiva
Computer Programming and Python FundamentalseasyMultiple ChoiceObjective-mapped

PCEP Function definition syntax Practice Question

Which of the following is the correct way to define a function that takes no arguments and returns the value 42?

⚠ Common exam trap

The trap here is that option B looks almost correct but is missing the mandatory colon. Candidates may overlook the colon and incorrectly select B as well. Only D is valid.

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

def f(): return 42

The syntax for defining a function in Python requires the def keyword, followed by the function name, parentheses (even if no arguments), a colon, and the indented body. Option B is missing the colon after the parentheses, making it syntactically incorrect.

Answer analysis

Option-by-option breakdown

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

  • function f(): return 42

    Why it's wrong here

    Incorrect because it uses the keyword 'function' instead of 'def' and is missing the colon.

  • def f() return 42

    Why it's wrong here

    Incorrect because it is missing the colon after the parentheses.

  • def f: return 42

    Why it's wrong here

    Incorrect because it is missing the parentheses after the function name.

  • def f(): return 42

    Why this is correct

    Correct because it uses `def`, parentheses, colon, and the return statement.

About these practice questions

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

Senior Network & Security Engineer · founder of Courseiva

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.