PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
What is the output of the following code? print(type(3.0) == float)
⚠ Common exam trap
Python Institute often tests the distinction between `type()` returning a class object versus a string representation, and candidates mistakenly think `type(3.0)` returns the string `'float'`, leading them to choose `False` or `Error`.
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
✓
True
The expression `type(3.0) == float` compares the result of `type(3.0)` (which is `<class 'float'>`) directly to the `float` class. In Python, `type()` returns the class object, and comparing it with `==` to the built-in class `float` yields `True` because they are the same object. Therefore, `print(True)` outputs `True`.
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 'bool'>
Why it's wrong here
The print call outputs the result of the comparison, which is the Boolean value True, not the string <class 'bool'>. That string would appear only if type() were applied to a Boolean. This option is tempting because the expression involves types, but the comparison itself yields True.
- ✗
False
Why it's wrong here
type(3.0) returns the float class object, and float is the same class object, so the equality comparison evaluates to True, not False. This option is tempting if 3.0 is mistaken for an integer, but the decimal point makes it a float, matching float exactly.
- ✗
Error
Why it's wrong here
The comparison type(3.0) == float is valid Python: type(3.0) returns the float class, and comparing it to float yields a Boolean. No exception is raised, so no error occurs. This option is tempting if the syntax looks unusual, but equality comparison between a type object and a class is legal.
- ✓
True
Why this is correct
The literal 3.0 is a floating-point number, so type(3.0) returns the float class object. Comparing that class object with float using == tests identity of the same built-in type, yielding True. This satisfies the stem's requirement to evaluate the expression's actual output.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
3 more ways this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. What is the output of print(type(3 + 4.5))?
hard- A.<class 'int'>
- B.<class 'complex'>
- ✓ C.<class 'float'>
- D.<class 'str'>
Why C: In Python, when you add an integer (3) and a float (4.5), implicit type conversion (coercion) occurs: the integer is promoted to a float to avoid data loss. The result is 7.5, which is a float. Therefore, type(7.5) returns <class 'float'>.
Variation 2. What is the type of the result of the expression 5 + 3.0?
easy- A.str
- ✓ B.float
- C.int
- D.complex
Why B: In Python, when an integer (int) and a float are combined using the addition operator, the result is implicitly converted to a float to preserve precision. Since 3.0 is a float, 5 + 3.0 yields 8.0, which is of type float.
Variation 3. Given the code: x = 10; y = 3.0; z = x / y; print(type(z)). What is the output?
hard- A.<class 'str'>
- ✓ B.<class 'float'>
- C.<class 'complex'>
- D.<class 'int'>
Why B: In Python, when you divide an integer by a float using the / operator, the result is always a float. Here, x is an integer (10) and y is a float (3.0), so z = 10 / 3.0 evaluates to 3.3333333333333335, which is of type float. The print(type(z)) outputs <class 'float'>, making option B correct.
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.