ProgrammingModerateInfosys · Accenture · Capgemini pattern
What is printed?
What is printed?
nums = [3, 1, 2] print(nums.sort())
- A. [3, 2, 1]
- B. [3, 1, 2]
- C. None
- D. [1, 2, 3]
Correct answer: C. None
list.sort() sorts in place and returns None, so the print shows None. Use sorted(nums) to get a new sorted list back.
More Python Programming questions
- What is printed? python print([x x for x in range(5) if x % 2])
- What is printed? python s = "hello" print(s[::-2])
- What is printed? python t = (1,) print(type(t).name, type((1)).name)
- What is printed? python def f(args, kw): print(len(args), len(kw)) f(1, 2, a=3)
- What is printed? python print(list(zip([1, 2, 3], "ab")))
- What is printed? python print(" ".join(sorted(set("banana"))))