ACTIVITY 31 / 50
Try as many times as you needEdit a list
Let’s understand
You can change a list after creating it. insert(index, value) adds an item before that position. pop(index) removes and returns an item; without an index it removes the last item. Later indexes shift after removal. Print the list after each change to inspect the order.
Listen to the explanation
Example
bag = ["map", "water"]
bag.insert(1, "torch")
last = bag.pop()
print(last)
print(bag)Insert "camera" at index 1 in tools. Remove the last item with pop. Print the removed item, then the final list.
I need a hint
Save the value returned by pop. Remember that indexes start at zero.
How to find an error
- Read the last line of the error message.
- Find the indicated line. Check quotes, parentheses and indentation.
- Change one thing and run again.
main.py
4 spaces
Your draft stays in this browser.
Result
PythonYour program’s output will appear here. Click Run.
Мой профиль