Practice question · Select all that apply
Which operations modify a Python list in place?
Hints
- Ask whether each call returns a new object or changes the original.
- An operation that only reports something cannot be modifying anything.
Show the answer
- C. reverse()
- D. append(x)
Why
sorted() returns a new list; len() only reads. append and reverse mutate.
Practise Lists, arrays, and structured storage
The app has 6 more questions on this lesson, and keeps your place in the course. Physics I is free to start.
More questions on Lists, arrays, and structured storage
- Accessing an element by index in an array takes O(n) time.
- Appending to the end of a list is cheap; inserting at the front is expensive. What about the storage layout…
- After b = a and b.append(4), printing a shows the 4 as well. What has actually happened?
- Sort these Python types into Mutable or Immutable.