LearnFrenzy
Sign in Take a free test

Lists · Predict the Output · Question 3

Assigning the result of sort() Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

What is the output of the following Python program?

main.py
a = [3, 1, 2]
b = a.sort()
c = sorted(a, reverse=True)
print(a, b, c)
  • A [3, 1, 2] [1, 2, 3] [3, 2, 1]
  • B [1, 2, 3] [1, 2, 3] [3, 2, 1]
  • C [1, 2, 3] None None
  • D [1, 2, 3] None [3, 2, 1] Correct
Correct Answer: Option D

sort() changes a and returns None; sorted() returns a new list.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links