ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
try:
print(sorted([3, None, 1]))
except TypeError:
print('TypeError')
print(max(['b', 'a'], key=str.upper), min([[2], [1, 9]]))- A. TypeError | a [2]
- B. 3 | b [1, 9]
- C. TypeError | b [2]
- D. TypeError | b [1, 9]
Correct answer: D. TypeError | b [1, 9]
Python 3 cannot compare None with an int, so sorted raises TypeError. max uses the upper-cased keys and picks b, and lists compare element by element, so [1, 9] is smaller than [2].
More Python Programming questions
- What is printed? python s = 'hello' try: s[0] = 'j' except TypeError: print('immutable') t = s.replace('h', 'j') print(t, s)
- What is printed? python print(1020 / 1019, 1020 // 1019, 264 % 1000, 1020 == 1e20)
- What is printed? python calls = [] def f(x): calls.append(x) return x 2 m = map(f, [1, 2, 3]) print(calls) first = next(m) print(calls…
- In Python, when is the outermost iterable of a generator expression such as (x for x in make()) evaluated?
- What is printed? python class Countdown: def init(self, n): self.n = n def iter(self): while self.n > 0: yield self.n self.n -= 2 c =…
- What is printed? python from itertools import permutations p = sorted(permutations('cab')) print([''.join(x) for x in p][3], len(p))