ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
import operator
print(operator.index(5), operator.mod(-7, 3), operator.floordiv(-7, 3))
  1. A. 5 -1 -2
  2. B. 5 2 -2
  3. C. 5 1 -3
  4. D. 5 2 -3

Correct answer: D. 5 2 -3

operator.index returns the int itself. Python's % gives a result with the divisor's sign, so -7 mod 3 is 2, and floor division of -7 by 3 is -3.

More Python Programming questions

Exams that ask this topic