What is the output of the following code? print(type(3.0) == float)
Correct; type returns <class 'float'>, which equals float.
Why this answer
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`.
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`.
How to eliminate wrong answers
Option A is wrong because `print()` outputs the value of the expression, not its type; the expression evaluates to `True`, which is a boolean, but the output is the string representation `True`, not `<class 'bool'>`. Option B is wrong because the comparison `type(3.0) == float` is `True`, not `False`; a common mistake is thinking `type()` returns a string like `'float'`, but it returns the actual class object. Option C is wrong because the code is syntactically valid and runs without any error; `type(3.0)` is a valid call, and comparing it with `==` to `float` is allowed.