ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
try:
print(sorted([3, None, 1]))
except TypeError:
print('cannot compare')- A. [None, 1, 3]
- B. cannot compare
- C. [1, 3, None]
- D. TypeError
Correct answer: B. cannot compare
Python 3 does not order None against numbers, so sorted raises TypeError. The except branch prints the message, and TypeError itself is not printed.
More Python Programming questions
- What is printed? python print('%(a)s-%(b)05.1f' % {'a': 'x', 'b': 3.14159})
- What is printed? python s = 'Ünïcödé' print(len(s), len(s.encode()), s.upper() == 'ÜNÏCÖDÉ')
- What is printed? python print(int('10', 2), int('0o17', 0), int('17', 8), int('0xff', 16))
- What is printed? python x = 0xDEAD print(x >> 8 & 0xFF, (x >> 8) & 0xF, hex(x & -x))
- What is printed? python print(sorted([-3, 2, -1, 4], key=lambda v: (abs(v) % 3, v)))
- What is printed? python print(f'{1234.5:,.2f}', f'{0.000123:.2e}', f'{-0.0:+.1f}', f'{0x123456:x}')