Questions: List Operations and Methods

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A programmer writes: words = ['banana', 'apple', 'cherry']; words = words.sort(); print(words). What does this print?

A['apple', 'banana', 'cherry'] — sort() returns the sorted list
BNone — sort() modifies the list in place and returns None, so words is now None
C['banana', 'apple', 'cherry'] — sort() on strings is not supported
DAn error — you cannot sort a list and reassign it in one line
Question 2 Multiple Choice

You have the list [3, 1, 4, 1, 5] and call remove(1). What is the resulting list?

A[3, 4, 5] — remove() deletes all occurrences of the value
B[3, 4, 1, 5] — remove() deletes the first occurrence of the value
C[3, 1, 4, 5] — remove() deletes the last occurrence of the value
D[1, 4, 1, 5] — remove() deletes the element at index 0 (the first 3)
Question 3 True / False

sorted(my_list) modifies my_list in place and returns the sorted version of the same list.

TTrue
FFalse
Question 4 True / False

pop() called with no argument removes and returns the last element of the list.

TTrue
FFalse
Question 5 Short Answer

What is the difference between remove() and pop(), and when would you choose one over the other?

Think about your answer, then reveal below.