Shopping List (Exercise)
00:00 In this exercise, you’ll practice using Python to create and edit your shopping list. Note that I mentioned edit. So this is actually going to be about lists because remember that tuples are immutable, but lists are mutable.
00:13
So you’ll be able to edit this list. Start off by creating a list named food
, and it should have two elements in it: "rice"
and "beans"
.
00:21
Then you can append the string "broccoli"
to food
using the .append()
method. Then also add the strings "bread"
and "pizza"
to food
, using the .extend()
method, and then display the first two items in the food
list using slice notation.
00:35
And finally, display the last item in food
using index notation.
Become a Member to join the conversation.