ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
from functools import total_ordering
@total_ordering
class V:
    def __init__(self, n):
        self.n = n
    def __eq__(self, o):
        return self.n == o.n
    def __lt__(self, o):
        return self.n < o.n
print(V(2) >= V(1), V(1) > V(1), max(V(3), V(7)).n, sorted([V(5), V(2)])[0].n)
  1. A. False False 7 2
  2. B. True True 7 2
  3. C. True False 3 2
  4. D. True False 7 2

Correct answer: D. True False 7 2

total_ordering builds >= from < and ==, so 2 >= 1 is True. 1 > 1 is False, and max and sorted use the same ordering.

More Python Programming questions

Exams that ask this topic