ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(sorted('bca'), ''.join(sorted('bca', reverse=True)), sorted([3, 1, 2], reverse=True)[0], list(reversed('ab')))- A. ['a', 'b', 'c'] abc 3 ['a', 'b']
- B. ['a', 'b', 'c'] cba 3 ['b', 'a']
- C. ['c', 'b', 'a'] cba 1 ['b', 'a']
- D. ['a', 'b', 'c'] cba 2 ['a', 'b']
Correct answer: B. ['a', 'b', 'c'] cba 3 ['b', 'a']
sorted on a string gives a list of single characters in order. Joining the reverse-sorted characters gives cba, and the largest of 3, 1, 2 is 3. reversed returns an iterator, and list() shows its elements in reverse order.
More Python Programming questions
- What is printed? python print(int('12') + int('3'), '12' + '3', 12 + 3 == int('15'), 'x')
- What is printed? python s = 'Python' print(s[0], s[-1], s[1:4], s[::2])
- What is printed? python print(len([1, 2, 3] 2), [1, 2] + [3], [0] 0, [[0] 2] 2 == [[0, 0], [0, 0]])
- What is printed? python print('Hello'.lower() == 'hello', 'Hello'.islower(), 'hello'.isalpha(), 'h3llo'.isalnum())
- What is printed? python print(0.1 + 0.2 > 0.3, round(0.1 + 0.2, 2) == 0.3, 3 0.1 == 0.3, 1 / 3 3 == 1)
- What is printed? python print(max([]) if False else 'none', min([5, 2, 8]), sum([]), sum([[1], [2]], []))