Which of the following expressions mutate, i.e., change, list my_list?
my_list + [10, 20]
Every class definition should include an initializer method. Is _init_ that method?
We can loop over strings, too!
The following incomplete function is a simple, but inefficient, way to reverse a string. What line of code needs to replace the questions marks for the code to work correctly?
"""Returns the reversal of the given string."""
[blank_start]result[blank_end] = ""
for char in s:
result = char + result
Imagine a game on a map. At the beginning, we might want to randomly assign each player a starting point. Which of the following expressions may we use in place of the question marks to correctly implement this functionality?
"""Returns a random point on a 100x100 grid."""
return (random.randrange(100), random.randrange(100))
"""Returns a list of random points, one for each player."""
points = 
for player in players:
point = random_point()
points + point
points += point
The following function is supposed to check whether the given list of numbers is in ascending order. For example, we want is_ascending([2, 6, 9, 12, 400]) to return True, while is_ascending([4, 8, 2, 13]) should return False.
"""Returns whether the given list of numbers is in ascending order."""
for i in [blank_start]range(len(numbers)[blank_end]):
if numbers[i+1] < numbers[i]:
However, the function doesn't quite work. Try it on the suggested tests to verify this for yourself. The easiest fix is to make a small change to the highlighted code. What should it be replaced with?