TypeError: can only concatenate list (not “str”) to list

后端 未结 5 627
情深已故
情深已故 2020-12-06 09:24

I am trying to make an inventory program to use in an RPG. The program needs to be able to add and remove things and then add them to a list. This is what I have so far:

5条回答
  •  再見小時候
    2020-12-06 10:05

    That's not how to add an item to a string. This:

    newinv=inventory+str(add)
    

    Means you're trying to concatenate a list and a string. To add an item to a list, use the list.append() method.

    inventory.append(add) #adds a new item to inventory
    print(inventory) #prints the new inventory
    

    Hope this helps!

提交回复
热议问题