PCEP-30-02 · Question #278
What is the expected output of the following code? print(type(+1E10)) print(type(5.0)) print(type('True')) print(type(False))
The correct answer is A. <class 'float'> <class 'float'> <class 'str'> <class 'bool'>. Option A is correct because Python treats any number written in scientific notation (like 1E10) as a float, regardless of the leading + sign - the result has no decimal point visually, but it's still a floating-point value. 5.0 is unambiguously a float, 'True' is a str because…
Question
Options
- A<class 'float'> <class 'float'> <class 'str'> <class 'bool'>
- B<class 'int'> <class 'float'> <class 'bool'> <class 'bool'>
- C<class 'int'> <class 'float'> <class 'str'> <class 'bool'>
- D<class 'float'> <class 'float'> <class 'bool'> <class 'bool'>
How the community answered
(46 responses)- A85% (39)
- B2% (1)
- C4% (2)
- D9% (4)
Explanation
Option A is correct because Python treats any number written in scientific notation (like 1E10) as a float, regardless of the leading + sign - the result has no decimal point visually, but it's still a floating-point value. 5.0 is unambiguously a float, 'True' is a str because the quotes make it a string literal rather than a boolean, and False (capital F, no quotes) is Python's built-in boolean literal, giving bool.
Why the distractors fail:
- B and C both claim
+1E10isint, but scientific notation always produces afloatin Python - you can verify withtype(1E0). - D claims
'True'isbool, but quotes always create astr; only the bare keywordsTrueandFalse(no quotes) produce abool.
Memory tip: Use the phrase "Quotes kill the bool" - any value wrapped in quotes is a str, no matter how boolean-looking it is. And remember "E means float" - scientific notation (E or e) always produces a float, never an int.
Community Discussion
No community discussion yet for this question.