Python lists can also be changed by calling their methods. Three methods in particular see frequent use:
append
method adds an element to the end of the list. For example, if example
is
[1, 2]
, the call example.append(0)
would change example
to
[1, 2, 0]
.pop
method removes and returns the last element from the list when given no arguments, or, if
it is given an index as an argument, removes and returns the element at that index. For instance, if
example
is [1, 2]
, the call example.pop()
would change
example
to [1]
and return 2
. Similarly, if sample
is
[1, 2, 3, 4]
, the call sample.pop(2)
would change sample
to
[1, 2, 4]
and return 3
.sort
method sorts a list in place (i.e., by changing it, not by making a separate,
sorted copy). For example, if example
is [3, 1, 4, 2]
, the call
example.sort()
would change example
to [1, 2, 3, 4]
.Fill in the placeholders so that the actual outputs match the expected outputs.