Courseiva

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

A developer writes the following code: x = 5; y = x; x = 10. What are the values of x and y after execution?

⚠ Common exam trap

Python Institute often tests the misconception that `y = x` creates a persistent link between variables, leading candidates to incorrectly assume `y` changes when `x` is reassigned.

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

✓

x = 10, y = 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 = 10` is executed, it binds the name `x` to a new integer object 10, while `y` still references the original object 5. Thus, after execution, `x` is 10 and `y` is 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.

  • ✓

    x = 10, y = 5

    Why this is correct

    Assignment binds the name y to the integer object 5, not to the variable x. Rebinding x to 10 therefore leaves y untouched, so x = 10 and y = 5. This satisfies the stem's constraint that integers are immutable and assignment copies the reference, not a live link.

  • ✗

    x = 5, y = 10

    Why it's wrong here

    Assignment copies the value 5 into y, and rebinding x to 10 afterwards leaves y untouched at 5. The reversed pairing swaps the variables, which would only occur if the second statement assigned x into y after the rebinding, not before it.

  • ✗

    x = 5, y = 5

    Why it's wrong here

    Rebinding x to 10 after y = x leaves y holding the original 5, so x cannot remain 5. This pairing reflects the mistaken belief that reassigning x also updates y, confusing Python's independent name binding with a shared reference.

  • ✗

    x = 10, y = 10

    Why it's wrong here

    y = x copies the value 5 into y at that moment; later rebinding x to 10 does not propagate to y. This pairing would hold only if both names referenced one shared mutable object whose contents changed, which integers do not.

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.