ProgrammingHardPython · GATE DA
What is printed?
What is printed?
print(1 < 2 < 3, 3 > 2 > 2, 1 == 1 in [1], not 1 == 2, 2 ** 3 ** 2)
- A. True False True True 64
- B. True False False True 512
- C. True False True True 512
- D. True False True False 512
Correct answer: C. True False True True 512
Chained comparisons are joined with and (3 > 2 > 2 is False; 1 == 1 in [1] is True); ** is right associative, so 2 ** 3 ** 2 = 2 ** 9.
More Python Programming questions
- What is printed? python a = [[0] 2] 2 a[0][0] = 1 b = [[0] 2 for in range(2)] b[0][0] = 1 print(a, b)
- What is printed? python def f(n): try: if n == 0: raise ValueError return 10 // (n - 1) except ZeroDivisionError: return -1 except…
- What is printed? python a, b, c = range(5) x, (y, z) = 1, 'hey' print(a, b, c, x, y, z)
- What is printed? python from collections import Counter c = Counter('mississippi') print(c.mostcommon(2), c['z'], sorted(c.items())[:2])
- What is printed? python pts = [(2, 1), (1, 5), (2, 0), (1, 2)] print(sorted(pts, key=lambda p: (-p[0], p[1])), max(pts, key=lambda p: p[1]))
- What is printed? python import copy a = {'k': [1, 2]} b = a.copy() c = copy.deepcopy(a) a['k'].append(3) a['j'] = 0 print(b, c)