Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Challenge Solution

Leo Yun Tao
Leo Yun Tao
15,956 Points

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

.

1 Answer

Steven Parker
Steven Parker
231,268 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.