0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
.pop()
is the opposite of .append()
. Pop removes the last element from a list and returns it for use. For example:
vegetables = ["broccoli", "cabbage", "kale", "tomato"]
last_vegetable = vegetables.pop()
# vegetables = ['broccoli', 'cabbage', 'kale']
# last_vegetable = 'tomato'
Our player is selling the items in their inventory to the shopkeep!
Pop the last element from the inventory
list until there is nothing left. Pop the elements into an item
variable so that each prints in turn on line 19
.
While .pop()
typically removes the last item of a list, it can also be used to remove an item at a specific index. For example, vegetables.pop(1)
would remove "cabbage"
from the list. This can be useful when you need to remove items from other positions in your list.
Focus Editor
Alt+Shift+]
Become a member to Submit
Become a member to Run
Become a member to view solution