Courseiva

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

A programmer writes: x = 5; y = x; x = 3; print(y). What is the output?

⚠ Common exam trap

Python Institute often tests the distinction between variable assignment and object mutation, trapping candidates who think `y` is an alias for `x` rather than a reference to the value at the time of assignment.

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

✓

5

In Python, integers are immutable, and the assignment `y = x` copies the reference to the integer object 5, not the variable itself. When `x` is later reassigned to 3, `y` still points to the original integer object 5, so `print(y)` outputs 5.

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

    Assignment binds y to the integer object 5, not to the variable x; rebinding x to 3 leaves y unchanged, so the output is 5. The value 3 is tempting because it is the last value assigned to x, and this option would be right only if y held a reference to the variable itself rather than the object.

  • ✗

    8

    Why it's wrong here

    Python assignment copies the object reference, not the value, so y stays bound to 5; no arithmetic combines the two assignments, and 8 never appears. Summing is tempting because the stem shows two numbers, and this option would fit a question asking for x + y after both assignments executed.

  • ✓

    5

    Why this is correct

    Assignment copies the value, not a reference, so y holds 5 independently of x. Rebinding x to 3 afterwards leaves y unchanged, printing 5. This reflects Python's immutable integer semantics, where each name points to a separate object.

  • ✗

    None

    Why it's wrong here

    The output is 5, because y is bound to the integer object 5 and rebinding x to 3 leaves y unchanged; integers are immutable. None is tempting as the default return of functions, but no function is called here, so it never appears.

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 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.