Removing item by value
Previously, we removed items from the inventory by index, but itβs also possible to remove items from the inventory by value.
The inventory can contain objects like cat
, dog
, monkey
, chicken
, parrot
, etc. So, if you want to remove dog from the inventory, you can simply write ninja.inventory.remove("dog")
.
Swipe to start coding
Solution
Explore other courses in Catalog
Thanks for your feedback!
ninja.py
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
How do I handle errors if the item is not in the inventory?
Can I remove multiple items at once by value?
What happens if there are duplicate items in the inventory?
Awesome!
Completion rate improved to 2.94
Removing item by value
Swipe to show menu
Previously, we removed items from the inventory by index, but itβs also possible to remove items from the inventory by value.
The inventory can contain objects like cat
, dog
, monkey
, chicken
, parrot
, etc. So, if you want to remove dog from the inventory, you can simply write ninja.inventory.remove("dog")
.
Swipe to start coding
Solution
Explore other courses in Catalog
Thanks for your feedback!
ninja.py