ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
import functools
@functools.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(1) <= V(1), V(2) >= V(3), sorted([V(3), V(1)])[0].n, V(1) != V(1))
  1. A. True True 1 False
  2. B. TypeError
  3. C. True False 1 False
  4. D. False False 1 True

Correct answer: C. True False 1 False

total_ordering fills in <=, >, >= from __lt__ and __eq__. != is derived from __eq__ automatically in Python 3.

More Python Programming questions

Exams that ask this topic