Find the output of the following Python code: L1=[1,4,3,2] L1.sort() L2=L1…

2023

Find the output of the following Python code: L1=[1,4,3,2] L1.sort() L2=L1 print (L2)

  1. A.

    [1, 4, 3, 2]

  2. B.

    [1, 2, 3, 4]

  3. C.

    1432

  4. D.

    1234

Attempted by 1855 students.

Show answer & explanation

Correct answer: B

Key insight: assigning L2 = L1 makes both names refer to the same list object, and list.sort() sorts the list in place.

  1. Create L1 = [1, 4, 3, 2].

  2. Assign L2 = L1 so L2 refers to the same list object as L1.

  3. Call L1.sort(), which sorts the list in place to [1, 2, 3, 4].

  4. print(L2) prints the current contents of that same list: [1, 2, 3, 4].

Final output: [1, 2, 3, 4]

Explore the full course: Rssb Senior Computer Instructor