nerdexam
Python_Institute

PCEP-30-02 · Question #64

The result of the following addition: 123 + 0.0

The correct answer is C. is equal to 123.0. When an integer and a float are added together, Python (and most languages) perform type promotion: the integer is automatically converted to a float before the operation, so the result is 123.0 - a float, not an integer. This makes C correct. A is wrong because the expression…

Question

The result of the following addition: 123 + 0.0

Options

  • Acannot be evaluated
  • Bis equal to 123
  • Cis equal to 123.0

How the community answered

(21 responses)
  • A
    14% (3)
  • B
    5% (1)
  • C
    81% (17)

Explanation

When an integer and a float are added together, Python (and most languages) perform type promotion: the integer is automatically converted to a float before the operation, so the result is 123.0 - a float, not an integer. This makes C correct.

A is wrong because the expression is perfectly valid - Python handles mixed int/float arithmetic without error. B is wrong because even though the numeric value is equivalent to 123, the type has changed: 123 is an int, while 123.0 is a float, and the question asks about the result of the addition (which is a float).

Memory tip: Think of it as the float "infecting" the result - any arithmetic involving a float always produces a float, no matter how small or trivial the float operand is. x + 0.0 is a common Python pattern used intentionally to force a value into float type.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice