ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
print(min([], default=0), max([2, 7], default=0), min("b", "a", key=ord), sum([[1], [2]], []))- A. 0 7 a [1, 2]
- B. ValueError
- C. 0 7 b [1, 2]
- D. 0 7 a TypeError
Correct answer: A. 0 7 a [1, 2]
default is returned only for an empty iterable. key=ord makes min compare code points, so 'a' wins. sum with a start value of [] concatenates the lists (slow, but legal; only str is refused by sum).
More Python Programming questions
- What is printed? python for kw in [{}, {"strict": True}]: try: print(list(zip("ab", [1, 2, 3], kw)), end=" ") except ValueError…
- What is printed? python def g(): yield from range(2) yield from "ab" return "done" def h(): r = yield from g() yield r print(list(h())…
- What is printed? python def evens(): n = 0 while True: yield n n += 2 def take(k, it): return [next(it) for in range(k)] e = evens()…
- What is printed? python def pipeline(): nums = (n for n in range(10)) sq = (n n for n in nums if n % 2) big = (s for s in sq if s > 10)…
- What is printed? python def g(): print("a", end=" ") x = yield print("b", x, end=" ") yield x 2 it = g() print(it.send(None), end=" ")…
- What is printed? python def g(): try: yield 1 except GeneratorExit: print("exit", end=" ") yield 2 it = g() next(it) try: it.close()…