ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(6 & 3 == 2, 5 | 2 == 7)
- A. False True
- B. True False
- C. True True
- D. 0 0
Correct answer: C. True True
In Python, & and | bind tighter than ==, so 6 & 3 == 2 means (6 & 3) == 2, which is True. C parses the same expression differently, which is the trap.
More Python Programming questions
- What is printed? python import heapq def medians(xs): lo, hi = [], [] out = [] for x in xs: heapq.heappush(lo, -x) heapq.heappush(hi…
- What is printed? python def sieve(n): s = bytearray([1]) (n + 1) s[0:2] = bytes(2) for i in range(2, int(n 0.5) + 1): if s[i]: s[i i::i] =…
- What is printed? python a = [1, 2, 3] b = a b += [4] c = a + [5] a = a 2 print(b, c, a)
- What is printed? python def stepstocycle(f, s): seen = {} i = 0 while s not in seen: seen[s] = i s = f[s] i += 1 return i, i - seen[s]…
- What is printed? python from collections import Counter def divpairs(a, k): c = Counter(x % k for x in a) total = 0 for r in c: s = (k…
- What is printed? python def isrot(a, b): return len(a) == len(b) and b in a + a print(isrot('abcde', 'cdeab'), isrot('abc', 'acb')…