- [Narrator ] A data type that we've
not yet discussed is the list data type.
A list lets us store multiple values inside
of a single variable.
As an example, let's create a list called inventory.
I'll say inventory and I'll say equals
and the list of inventory items was going to
be in brackets, not curly brackets but straight brackets.
I'm going to do an open straight bracket
and I'm going to list some inventory items.
Let's say because these are strings.
I'll say in quotes, I'll say catalyst
and we'll say that I've got a catalyst 3750 in inventory,
close quote and I separate the different items with a comma.
So I'll do a comma,
and then in quotes I'll say that I've got a catalyst 2960
close quotes, another comma separator,
and then in quotes I'll say that I've got a 2911 router,
close quotes, another comma,
and finally let's say that I've got a 7965 G IP phone
close quote and let's close our brackets.
We've now defined the items in our list
and we can see that this is a data top of list
by saying type and then I'll say
in parentheses inventory
and it says the clients, in other words,
the data type is list.
If I want to see all of the items
in my inventory in this list
from the interactive interpreter,
I can just enter the inventory name.
I can say inventory, so I just type in the name of the list
and it lists out all the items in my inventory.
However, if I were wanting to do this as part of a program,
I couldn't get away with that.
As part of a program, if I want to print something
on screen, I need to use the print function.
So in a program I would say print
and then in parentheses I would say inventory,
notice no quotes because inventory is not a string.
Inventory is the name of our list.
Which contains all of those different values.
If I want to see just a specific item in the list,
I could say inventory
and then in straight brackets I could say zero
and close the straight brackets.
That's going to give me the first inventory item.
It should display the catalyst 3750 and it does.
Again, if I wanted to do that as part of a program,
I would need to use the print function
and I would say inventory then I could do
the zero in brackets,
but as another example, let's do the number one.
It's important to remember the numbering begins at zero.
If I say one that should list the second item,
it should list the catalyst 2960.
So let's do a close bracket, close parentheses,
and it does tell us the catalyst 2960.
Oh by the way, we can also as a shortcut
and jumped to the end of the list.
I could say inventory and then in brackets
I could say negative one
or again we would put this inside of the parentheses
of a print function if we were doing this in a program,
but here we're at the interactive interpreter,
so we'll save those steps.
If I say inventory negative one,
it gives me the last item in the list.
If I say inventory in brackets, negative two,
that's going to give me the next to last item in the list.
I can overwrite an inventory item.
Let's say that I want to overwrite that first item.
Again, the numbering starts at zero,
so I'll say inventory and then in brackets zero
I'll say that equals the string of catalyst 3560.
So we're changing our 3750 to 3560
and if I say inventory now you see that it's been changed.
I can delete an item by saying D-E-L
and I'll say inventory
and I'll put three in brackets
and that should delete our fourth item.
It should delete our IP phone.
So let's say inventory again
and it's deleted our phone.
If I want to add something to this list,
I can say inventory dot append,
and then in parentheses I'm going to put in quotes
the string that I want to append to this list of items.
I'll say I want to add a CUCM,
which is a Cisco Unified Communications Manager Server,
close quotes, close parentheses, enter.
Let's see what our inventory looks like.
Now I'll say inventory.
And we see that we have added on the CUCM server
to the end of our inventory list.
And that's a look at the data type known as a list,
which lets us store multiple values
in a single variable.