ProgrammingModerateInfosys HackWithInfy · TCS CodeVita
What is printed?
What is printed?
print(() is (), [] is [], (1, 2) == (1, 2))
- A. True False True
- B. False False True
- C. True True True
- D. True False False
Correct answer: A. True False True
CPython reuses one empty tuple object, so () is () is True. Each [] creates a new list, so two empty lists are never the same object.
More Python Programming questions
- A program must answer 10^5 range-sum queries over an array of 10^5 numbers in CPython. Which approach is fastest?
- What is printed? python from functools import lrucache class C: @lrucache(maxsize=None) def f(self, x): return x 2 a, b = C(), C() a.f(1)…
- What is printed? python class A: def init(self, v): self.v = v def eq(self, o): return isinstance(o, A) and self.v == o.v xs = [A(1)…
- What is printed? python a, b = 5, 9 a ^= b b ^= a a ^= b print(a, b)
- What is printed? python nums = [10, 9, 100, 1] print(sorted(nums, key=str), max(nums, key=str), sorted(map(str, nums))[-1])
- What is printed? python def ngecirc(a): n = len(a) res = [-1] n st = [] for i in range(2 n): x = a[i % n] while st and a[st[-1]] < x…