Variables, Types & Operators · Question 7 · Easy

An integer is added to a float. What does Python print for the sum?

print(5 + 2.0)
  1. 7
  2. 52.0
  3. TypeError
  4. 7.0
Answer and explanation

Answer: D. 7.0

Explanation: When an int and a float are mixed, the int is widened to a float and the result is a float. So 5 + 2.0 is 7.0, not 7.

Previous: Applying the usual operator precedence, what does this arithmetic expression… · Next: Floor division and remainder are applied to a negative number. What is the…

Practise variables, types & operators

Try a fresh set of variables, types & operators questions with an explanation after every answer, free and without signing up: Variables, Types & Operators practice. Or sit a full placement mock test.

More variables, types & operators questions

More python practice

Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge