PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A developer writes: x = 5; y = 2.0; z = x / y; print(type(z)). What is the output?
⚠ Common exam trap
Python Institute often tests the distinction between / (true division, always returns float) and // (floor division, returns int for int operands) to catch candidates who assume integer division returns an integer.
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
✓
<class 'float'>
In Python, the division operator (/) always returns a float, even when dividing two integers. Here, x is an integer (5) and y is a float (2.0), so the result is a float (2.5). The type() function returns <class 'float'>, making D correct.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
<class 'str'>
Why it's wrong here
The / operator performs numeric true division, returning a float value, never a string. It is tempting because print() displays text and type() output resembles a string literal, but type() returns the actual class object, so the result is <class 'float'>, not <class 'str'>.
- ✗
<class 'int'>
Why it's wrong here
True division in Python 3 always returns a float, even when both operands are integers, so 5 / 2.0 yields 2.5, not an int. It is tempting because int divided by int historically produced an int in Python 2, but the / operator now performs float division, giving <class 'float'>.
- ✗
TypeError
Why it's wrong here
Dividing an int by a float is valid in Python 3 and returns a float, so no exception is raised. TypeError is tempting because mixing types often fails elsewhere, for example adding int and str, but true division always coerces operands to float, producing <class 'float'>.
- ✓
<class 'float'>
Why this is correct
Dividing an int by a float invokes Python's true division, which always yields a float regardless of whether the result is whole. Here 5 / 2.0 produces 2.5, so type(z) returns <class 'float'>. This satisfies the stem's mixed-type operand constraint, since int/float promotes to float.
Go deeper
Related to this question
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 →
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.