4/7 strange occurence


#1
def hotel_cost(nights):
    return 140 * nights
    
def plane_ride_cost(city):
    if city == "Charlotte":
        return 183
    elif city == "Tampa":
        return 220
    elif city == "Pittsburgh":
        return 222
    elif city == "Los Angeles":
        return 475
    else: print "Not found. Try again."
    
def rental_car_cost(days):
    cost = days * 40
    if days >= 7:
        cost -= 50
    elif days >= 3:
        cost -= 20
    return cost

What I don't understand, is that the last bit with cost requires -= instead of a regular = symbol.
It kept returning an error when it was only = .
I cannot find an explanation about this with google, and the course hasn't covered it so far.
What does this -= do? I have also seen it combined with * and + signs instead of -
Can anyone explain this?


#2

@bitrockstar98509

That -= sign means

a = 5

a = a + 5
# or
a += 5

b = 10

b = b - 5
# or
b -= 5

It also works with multiplication division and several other built-in methods.

EDIT:

I forgot to mention if you didn't figure it out that it basically tells python to work on the value stored in the variable directly along with the modifier, = is the assignment operator and when modified with the - it tells python i want you to modify the proceeding variable with a subtract this operation.