PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A developer wants to assign the value 3.14 to a variable and later change it to the integer 3. Which of the following is true?
⚠ Common exam trap
Many exam-takers confuse Python's dynamic typing with static typing rules from languages like Java or C, leading them to believe that type changes require explicit conversion or are disallowed.
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
✓
This is allowed because Python is dynamically typed.
Python is dynamically typed, meaning variables can be reassigned to values of any type at runtime. The developer can first assign the float 3.14 to a variable and later reassign the integer 3 to the same variable without any type declaration or conversion function required.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
This is allowed only if the variable was declared as a float.
Why it's wrong here
Python variables are dynamically typed, so a name bound to 3.14 can later be rebound to the integer 3 without any declaration. Declaring a float type is tempting because statically typed languages require it, but Python has no such declaration syntax; the type belongs to the object, not the name.
- ✗
This causes a TypeError because you cannot change types.
Why it's wrong here
Rebinding a name from a float to an int is legal in Python; no TypeError occurs because types attach to objects, not variables. The error is tempting because operations mixing incompatible types do raise TypeError, but plain reassignment performs no type check, so the change succeeds at runtime.
- ✓
This is allowed because Python is dynamically typed.
Why this is correct
Python variables are unbound names, so rebinding `pi` from the float 3.14 to the integer 3 is legal; the interpreter checks types at runtime, not at declaration. This satisfies the stem's requirement that the same name later hold a different type, which dynamic typing permits.
- ✗
This is allowed only if you use the int() function during assignment.
Why it's wrong here
Assignment needs no conversion function; writing x = 3 directly rebinds the name, and int() is only required when converting a value such as a string. The function is tempting because it does produce integers, but it is a conversion tool, not a prerequisite for reassigning a variable to a different type.
Go deeper
Related to this question
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 →
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.