A Python programmer is analyzing the results of several expressions. Which TWO of the following expressions evaluate to a float value? (Choose two.)
The floor division operator // returns a float if either operand is a float. Here, 4.0 is a float, so 4.0 // 2 yields 2.0, which is a float. Even though the operation is floor division, the presence of a float operand forces the result to be a float. Thus, this expression evaluates to a float value.
Why this answer
In Python, the / operator always returns a float, so 4 / 2 yields 2.0. Additionally, floor division // returns a float if either operand is a float, so 4.0 // 2 yields 2.0. The other expressions involve only integers and use operators that return integers when both operands are integers.
Thus, the expressions that evaluate to a float are 4 / 2 and 4.0 // 2.
Exam trap
The trap here is assuming that floor division always returns an integer, but when one operand is a float, the result is a float.