ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
try:
sorted([3, 'a'])
except TypeError as e:
print(e)- A. '<' not supported between instances of 'str' and 'int'
- B. '<' not supported between instances of 'int' and 'str'
- C. sorted() cannot compare int and str
- D. No output
Correct answer: A. '<' not supported between instances of 'str' and 'int'
For two elements Timsort compares the second with the first, so it evaluates 'a' < 3. Mixed types that cannot be ordered raise TypeError, and the message names the operands in the order they were compared.
More Python Programming questions
- A Python solution reads n = 10^6 numbers with input() in a loop, calling int(input()) for each line. Which change is the most effective…
- What is printed? python import math print(math.gcd(12, 18, 27), math.lcm(4, 6), math.gcd())
- What is printed? python print(divmod(-(10 20), 7))
- What is printed? python import heapq h = [4, 1, 3] heapq.heapify(h) print(h[0], sorted(h))
- What is printed? python from collections import deque d = deque([1, 2, 3, 4, 5], maxlen=3) d.append(6) d.appendleft(0) print(list(d))
- What is printed? python x = [0] 3 y = [[0] 2] 2 y[0][1] = 7 print(x, y)