ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(max('apple', 'banana', key=len), max(['x', 'yy', 'zz'], key=len), min([3, 1, 1.0], key=abs), max([1, 1.0], key=lambda v: v))- A. banana zz 1 1.0
- B. banana yy 1 1
- C. apple yy 1 1
- D. banana yy 1.0 1
Correct answer: B. banana yy 1 1
max with a key returns the first item with the largest key, so banana wins on length, and yy beats zz by coming first. min with key=abs keeps the first of equal keys, which is 1.
More Python Programming questions
- What is printed? python print(float('0.1') + float('0.2') == 0.3, float('0.30000000000000004') == 0.1 + 0.2…
- What is printed? python s = 'hello' print(s.index('l'), s.rindex('l'), s.find('z'), s.count('l'))
- What is printed? python print(int(str(264) 0 + '7') 2, len(str(7 100)), 7 100 % 10)
- What is printed? python from itertools import product print(list(map(''.join, product('ab', repeat=2))))
- What is printed? python print(sum(range(10 6)) % 1000, sum(range(1, 11)) // 5)
- What is printed? python print(('a' 'b' 'c').upper(), 'x' 'y' 2, ('%d' % 3) 2)