Courseiva

PCEP Practice Question: Data Types, Variables, Basic I/O and Operators

A program contains this code: print(1 and 2 or 3). What is the output?

⚠ Common exam trap

Python Institute often tests the misconception that `and`/`or` always return `True` or `False`, leading candidates to pick `True` (option C) instead of the actual operand value `2`.

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

✓

2

In Python, the `and` and `or` operators short-circuit and return the last evaluated operand, not a boolean. `1 and 2` evaluates to `2` because both are truthy and `and` returns the last truthy value. Then `2 or 3` short-circuits because `2` is truthy, so `or` returns `2` without evaluating `3`. Thus, the output is `2`.

Answer analysis

Option-by-option breakdown

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

  • ✗

    3

    Why it's wrong here

    Python's `and`/`or` return operands, not Booleans: `1 and 2` yields 2, and `2 or 3` short-circuits to 2, so the output is 2. Choosing 3 assumes `or` evaluates its right operand, which only happens when the left is falsy — tempting because `or` is often misread as always returning the final value.

  • ✗

    1

    Why it's wrong here

    and returns its second operand when the first is truthy, so 1 and 2 evaluates to 2, and 2 or 3 then returns 2. It is tempting because 1 is truthy and appears first, but short-circuit evaluation only returns the first operand when it is falsy.

  • ✗

    True

    Why it's wrong here

    Python's and/or return operands, not booleans, so 1 and 2 yields 2, then 2 or 3 yields 2; True never appears. It is tempting because and/or are logical operators, and True would be correct if the expression were wrapped in bool() or compared with a boolean context.

  • ✓

    2

    Why this is correct

    Python's `and` binds tighter than `or`, so `1 and 2` evaluates first. Since 1 is truthy, `and` returns its second operand, 2. That truthy result short-circuits the `or`, so 3 is never evaluated, satisfying the stem's precedence and short-circuit constraints.

About these practice questions

Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.