ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
t = 1, 2, u = (3) v = () w = (4,) * 0 print(type(t).__name__, len(t), type(u).__name__, v == w, (1, 2) < (1, 2, -1))
- A. tuple 2 int True True
- B. tuple 3 tuple True True
- C. tuple 2 int False True
- D. tuple 2 int True False
Correct answer: A. tuple 2 int True True
The comma makes the tuple, so `1, 2,` is a 2-tuple, while (3) is just the int 3. Every empty tuple is equal. A tuple that is a proper prefix of another is smaller.
More Python Programming questions
- What is printed? python class Err(Exception): def init(self, code): super().init(f"code {code}") self.code = code try: try: raise Err(7)…
- What is printed? python def check(v): assert v > 0, f"bad {v}" return v try: check(-1) except AssertionError as e: print("AE", e, end=" ")…
- What is printed? python it = iter([1, 2]) try: while True: print(next(it), end=" ") except StopIteration as e: print("stop", e.value…
- What is printed? python def f(): try: return [1] finally: pass def g(): x = [1] try: return x finally: x.append(2) def h(): x = 1 try…
- What is printed? (Output lines are shown separated by " / ".) python class P: def init(self, x): self.x = x def eq(self, o): return self.x…
- What is printed? python class V: def init(self, n): self.n = n def add(self, o): return V(self.n + o) def radd(self, o): return V(o 10 +…