Lists · practice
Add Items to a List
Replacing an item keeps the same .append()
Add one item to the end
.append() adds exactly one item at the end:
The existing list changes in place. After the call, packing refers to the three-item list. Keep the call on its own: .append() changes the list rather than returning a new list to packing = packing.append("toothbrush"), because that would replace the name’s reference to the list with the method’s
Call .append() again when another item arrives:
The calls run from top to bottom, so the appended items keep that order. The list grows one item at a time. Pleasantly literal, for once.
Which line adds "notebook" to the end of a list named supplies?
Watch the list grow
In the exercise, append two supplied items. Check their final order: the order of your calls becomes the order at the end of the list.
Task
Grow the existing packing
Append
"toothbrush"to the end.Append
"charger"to the end.Print the completed list.
The final order must be passport, shirt, toothbrush, charger.
If the items appear in the wrong order, press Step in the editor toolbar and watch the list grow after each call.