Difference in syntax Taking a Vacation, ex. 4


In completing exercise 4 of Taking a Vacation, an expression was used that seems on the surface to be functionally identical to what I initially used. My first effort attempted to use this syntax:

if (condition):
a == a - x

The correct answer used this syntax:

if (condition):
a -= x

What is the functional difference between the way these are processed? Why would the first not provide the correct answer, while the second does? As far as I have learned so far, they do the same thing, don't they?


The '==' is named the equal sign. You can only use it in true or false conditions like in if's.

But what you're trying is to assign a value to a variable.

you can use the '='.



Oh goodness. You're right. I was staring at that the whole time and didn't even notice that I was comparing instead of assigning. Thank you! :smile: