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))- A. True True 1 False
- B. TypeError
- C. True False 1 False
- 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
- What is printed? python def f(): l = [] for i in range(3): try: if i == 0: raise ValueError l.append(i) except ValueError: l.append("v")…
- What is printed? python def risky(n): if n == 1: raise KeyError(n) if n == 2: raise IndexError(n) return n res = [] for n in range(4)…
- What is printed? python class E(Exception): def str(self): return "custom" try: try: raise E("orig") except E as e: raise…
- What is printed? python def f(x): try: return int(x) except ValueError: return float(x) except TypeError: return -1 print(f("3")…
- What is printed? python import math print(math.isclose(0.1 + 0.2, 0.3), math.isclose(1e-10, 0), math.isclose(1e-10, 0, abstol=1e-9)…
- What is printed? python a = 0.1 + 0.2 print(f"{a:.20f}"[:6], a == 0.3, round(a, 15) == round(0.3, 15), str(a) == "0.30000000000000004"…