ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(max([1, 2], [1, 2, 0]) == [1, 2, 0], min((1, 'a'), (1, 'b')), sorted([(1, 'b'), (1, 'a')])[0][1])
- A. False (1, 'b') b
- B. True (1, 'a') a
- C. True (1, 'b') a
- D. True (1, 'a') b
Correct answer: B. True (1, 'a') a
Lists compare element by element, and [1, 2, 0] is longer than [1, 2], so it is the maximum. Tuples compare the second item when the first items tie, so (1, 'a') is the smallest.
More Python Programming questions
- What is printed? python print(3 [0] == [0, 0, 0], [0] 3 is [0] 3, 'a' in 'abc' in 'abcdef')
- What is printed? python print(sum([1, 2, 3]) / 2 // 1, 7 // 2 / 2, divmod(7.0, 2)[0] == 7 // 2)
- What is printed? python print('{:^6}'.format('ab'), '{:<4}'.format(1), '{:>3}|{:<3}|'.format('a', 'b'))
- What is printed? python print('a' < 'b' < 'c', 'b' > 'a' and 'b' > 'c')
- What is printed? python print(len([range(3), 'ab']), ['ab', [1]], {{'a': 1}, 'a': 2})
- What is printed? python print(hash(()) == hash(()), (1, 2) < (1, 2, 0), 'b' 2 > 'ab' 2, (1, 'b') < (1, 'a'))