Shorthand to Increase a Variable's Value?


#1

Why can’t I do

inventory['gold'] + 50

instead of

inventory['gold'] = inventory['gold'] + 50

?


FAQ: Learn Python: Python Lists and Dictionaries - It's Dangerous to Go Alone! Take This
FAQ: Learn Python: Python Lists and Dictionaries - It's Dangerous to Go Alone! Take This
#2

You can!

The shorthand for addition is +=

When I did this exercise inventory[‘gold’] += 50 worked like a charm.

Good luck!


#3

That’s perfect! Thanks!


#4

This topic is solved.