ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(max(['10', '9'], key=len), max(['10', '9']), max([10, 9], key=str))
- A. 10 10 9
- B. 10 9 10
- C. 10 9 9
- D. 9 9 9
Correct answer: C. 10 9 9
With key=len, '10' is the longest. Plain max compares strings, so '9' is larger than '10'. With key=str, the integer 9 is compared as the text '9', which beats '10'.
More Python Programming questions
- What is printed? python print(10 == 10.0 and 'a' == 'a', 1 < 2 or 1 / 0)
- What is printed? python print(sum(x for x in range(1, 101) if x % 3 == 0 or x % 5 == 0))
- What is printed? python print(int(float(253)) == 253, float(253 + 1) - 253, (253 + 1) - 253)
- What is printed? python print('a'.join('xyz'), 'xyz'.join(['a']), 'ab'.join(['', '']), ','.join(map(str, [1.0, 2])))
- What is printed? python print(round(0.5 3), round(4.5) + round(5.5), int(2.9999999999999996), int(3.0000000000000004))
- What is printed? python print('Python' 0 + 'x', 'Py' + 'thon' 0, len('' 100))