ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(max([], default=-1), min([3], default=0), sum([]), sum([], 0.0), any([]) or all([]))
- A. -1 3 0 0 True
- B. -1 3 0 0.0 False
- C. -1 3 0 0.0 True
- D. 0 3 0 0.0 True
Correct answer: C. -1 3 0 0.0 True
max and min accept a default for empty input, so max([], default=-1) is -1. sum([]) is the int 0, but sum([], 0.0) returns the float start value. any([]) is False and all([]) is True, so the or gives True.
More Python Programming questions
- What is printed on the first line? python words = ['apple', 'Bob', 'cat', 'Dog', 'ant'] print(sorted(words, key=lambda w: (w[0].lower()…
- What is printed on the second line? python nums = [5, -3, 0, 2, -3] print(sorted(nums, key=lambda x: x < 0)) print(sorted(nums, key=lambda…
- What is printed on the first line? python data = [('x', 3.0), ('y', 3), ('z', 2.5)] print(sorted(data, key=lambda t: t[1]))…
- What is printed? python s = 'level' t = ''.join(reversed(s)) print(s == t, s[::-1] is s, s[::-1] == t, s.count('l') s.count('e'))
- What is printed? python a = 1e308 b = a 10 print(b, -b, b - b if False else 0, b > a, b == float('inf'))
- What is printed? python import math print(math.sqrt(16), math.sqrt(2) 2 == 2, math.isqrt(2) 2 == 2, math.pow(2, 0.5) == 2 0.5)