ProgrammingHardCognizant GenC · TCS NQT
What is printed?
What is printed?
print([3, 1].sort() or 'x', sorted([3, 1]) == [1, 3])
- A. None True
- B. x False
- C. [1, 3] True
- D. x True
Correct answer: D. x True
list.sort returns None, which is falsy, so the or expression gives 'x'. sorted returns a new list [1, 3], so the comparison is True.
More Python Programming questions
- What is printed? python try: try: 1 / 0 except ZeroDivisionError: raise ValueError('bad') except ValueError as e…
- What is printed? python print(sorted([(1, 2), (1,), (0, 9, 9)]))
- What is printed? python print('abcabc'.find('c', 3, 5), 'abcabc'.rfind('a', 0, 4))
- What is printed? python d = {'a': {'b': 1}} print(d.get('a', {}).get('c', 0), d.get('x', {}).get('b'), d['a'].get('b'))
- What is printed? python import math def ndiv(n): c = 0 for i in range(1, math.isqrt(n) + 1): if n % i == 0: c += 1 if i i == n else 2…
- What is printed? python class N: def init(self, v, nxt=None): self.v, self.nxt = v, nxt def mid(h): slow = fast = h while fast and…