ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
x = 3.0
print(x.is_integer(), (3.5).is_integer(), int(x) is x, type(int(x)).__name__)
  1. A. True False True int
  2. B. True True False int
  3. C. True False False float
  4. D. True False False int

Correct answer: D. True False False int

is_integer checks whether a float has no fractional part, so 3.0 passes and 3.5 fails. int(x) makes a new int object, so it is not the same object as the float x, and its type is int.

More Python Programming questions

Exams that ask this topic