Python Challenge Solution

Leo Yun Tao
Leo Yun Tao
10,500 Points

Why do I get an error when I put array[index -= 1] rather than array[index - 1]

.

1 Answer

Steven Parker
Steven Parker
163,722 Points

The expression index -= 1 is an assignment which changes the value of index but the expression itself does not provide a value to select an array element with.

On the other hand, the expression index - 1 has a value that can be used to select an array element. And it provides a smaller value without changing the value of index itself.