ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = [3, 1, 2].sort() print(x, sorted([3, 1, 2]))
- A. [] [1, 2, 3]
- B. None None
- C. None [1, 2, 3]
- D. [1, 2, 3] [1, 2, 3]
Correct answer: C. None [1, 2, 3]
list.sort() sorts in place and returns None, so x is None. sorted() returns a new sorted list.
More Python Programming questions
- What is printed? python print(min([(1, 'b'), (1, 'a')], key=lambda t: t[0]), max(['aa', 'b', 'cc'], key=len))
- What is printed? python d = dict.fromkeys(['a', 'b'], []) d['a'].append(1) print(d)
- What is printed? python list = [1] try: print(list(range(2))) except TypeError as e: print(e)
- What is printed? python import heapq g = {'A': [('B', 1), ('C', 4)], 'B': [('C', 2), ('D', 5)], 'C': [('D', 1)], 'D': []} dist = {k…
- What is printed? python print(pow(10, 100, 7), pow(2, 10, 1000), pow(7, 0, 7))
- What is printed? python x = 5 print(x if x > 3 else 0 if x == 3 else -1, 2 -1, 7 % 3 2)