ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(10 ** 17 in range(0, 10 ** 18, 2), 10 ** 17 + 1 in range(0, 10 ** 18, 2))
  1. A. False False
  2. B. False True
  3. C. True False
  4. D. True True

Correct answer: C. True False

A range containment test for ints is a constant-time arithmetic check: it verifies the bounds and that (x - start) is a multiple of the step. 10**17 is even, while 10**17 + 1 is not.

More Python Programming questions

Exams that ask this topic