ProgrammingHardGATE CS · Product-company placement
Which of these expressions raises an exception in Python 3?
- A. sorted(['b', 'A', 'a'])
- B. max([[], [0]])
- C. min((2, 'x'), (1, 5))
- D. sorted([3, None, 1])
Correct answer: D. sorted([3, None, 1])
Python 3 does not define ordering between None and int, so sorting [3, None, 1] raises TypeError. Strings order by code point, lists compare lexicographically, and the tuple comparison is decided by the first elements 2 vs 1 before reaching 'x' vs 5.
More Python Programming questions
- Which statement about the C3 method resolution order is correct for class D(B, C) where both B and C inherit from A?
- Which is the safest way to remove every even number from a list nums in place (so that other references to the same list see the change)?
- What is printed? python import sys a = [] b = a c = [a, a] print(sys.getrefcount(a) - sys.getrefcount([]) >= 3, c[0] is c[1], [a] == [b])
- What is printed? python x = (1, 2, 3) y = x + (4,) z = x 0 print(len(y), z, x.count(2), x.index(3), 3 in x)
- What is printed? python s = "a1b22c333" digits = "".join(ch for ch in s if ch.isdigit()) letters = [ch for ch in s if ch.isalpha()]…
- What is printed? python def f(n, memo={}): if n in memo: return memo[n] r = n if n < 2 else f(n - 1) + f(n - 2) memo[n] = r return r f(10)…