14/14 It's Dangerous to go alone - Gold question


When doing this exercise, it asked to add 50 to the total gold value. I tried doing various means with the .append() command but the page always bounced back an error of some kind. After searching here, this was the solution everyone seemed to use:

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

Why can't you use the append function here?


hasattr('append', 97) # False, an integer does not have an "append" attribute
hasattr('append', []) # True
[].append(5) # OK
(97).append(5) # What's this even supposed to do?


So basically you just can't do an append if you're trying to append an integer?


Mmmh no.

You have some object. Let's call it bob.

Let's ask bob to append 5:


If bob is a list, that will succeed. But if bob is an integer, then it'll crash, because an integer has no "append" attribute.