Adding keys to a list


Hallo dear codacademy community

I am currently working my way through the basic Python coding tutorial when I was wondering about something.
(Please refer to Learn Python 2, Python Lists and Dictionaries, Exercise 14: It’s Dangerous to Go Alone! Take This)

To add a string to a list you go like this (EXAMPLE only):

inventory = {
‘gold’ : 500,
‘pouch’ : [‘flint’, ‘twine’, ‘gemstone’], # Assigned a new list to ‘pouch’ key
‘backpack’ : [‘xylophone’,‘dagger’, ‘bedroll’,‘bread loaf’]

inventory[‘backpack’].append(“shovel”) # This will add the string “tree” to the key ‘pocket’ in the list inventory.

Why can’t I add an integer the same way? Just like:


Thanks for your help!


because methods like .append() are data type specific. You increase/add gold with math operation


Thank you :slight_smile:


Once you learn about classes and methods (functions belonging to class(es)), this should make more sense, but i won’t explain it, given it might just be confusing at this point, the course will cover it later