ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
try:
print(sorted([3, None, 1]))
except TypeError as e:
print(e)- A. [1, 3, None]
- B. '<' not supported between instances of 'int' and 'NoneType'
- C. [None, 1, 3]
- D. '<' not supported between instances of 'NoneType' and 'int'
Correct answer: D. '<' not supported between instances of 'NoneType' and 'int'
sorted compares the second element with the first first, so it evaluates None < 3, which is not supported. The message names NoneType on the left.
More Python Programming questions
- What is printed? python def flat(x): for y in x: if isinstance(y, list): yield from flat(y) else: yield y print(list(flat([1, [2, [3…
- What is printed? python print(len(str(int('7' 4300)))) try: int('7' 4301) except ValueError: print('no')
- What is printed? python print(round(0.25, 1), round(0.35, 1), round(2.5), round(-0.5))
- What is printed? python d = {'a': 1, 'b': 2} d['a'] = 3 d.pop('a') d['a'] = 4 print(list(d.items()))
- What is printed? python print({k % 4: k k for k in range(9, -1, -1)})
- What is printed? python print(sum([0.1] 10) == 1.0, 0.1 3 == 0.3)