Welcome back.
Let's keep going with some more stirring methods now we've learned about adding and removing ones.
We learned about append, insert and extend and then removing.
We learned about pop, remove and clear.
There's a few other important ones.
Let's go with the index.
So instead of clearing here, let's clean this up.
And we'll do basket dot.
An index, as you can see, we give it a value, a start and a stop, what does that mean?
Well, we want to say, hey, what index is number two?
If we do index of two and I click run.
It's going to give me one I know this is a little confusing, but it's asking for the index.
Where is number two?
Number two is that index of one, let's change these into letters just so it's more clear.
So we have A B.
D and then finally, E!
And again, if I do.
D here and I click run.
I get an index of three because zero one, two, three, it's on shelf three in our memory and you can
also do a optional parameter here, which is where should we start looking?
So I want you to start looking at index of zero and then finish looking at index of two.
If I do run here, I get an there.
It says, hey, D is not enlist because while we started at index of zero and stopped it index of two.
If I do three and I click run.
No, it stops right before 3:00, so if I do for.
And I click Ron.
There you go.
I get three.
Now, errors are not good in our programs.
Ideally, we don't want to get errors, so how do we avoid this?
What if we're looking for something and we're not sure if it's in the list or not?
There's another nifty way of looking for things in a list.
And this involves what we call a python.
Key word.
A key word is something that you use in Python that, well, already has some meaning.
For example, a key word here, if I go to Python, key words are all these words that already mean
something.
Now we're going to go through them and we haven't seen a lot of them yet.
But you might have seen true right in boolean values to mean something.
So in Python, we can't really use the word true because, well, it already means something.
There's a word called in that, as you can see, as soon as we type means something as a key word in
Python and this is quite nice, we can say, hey, is D. in the basket and if I run this.
I get true, OK, is X in Baskett.
I get false because, well, it doesn't exist and this is actually quite useful and we can even do it
for strings.
For example, if I'm looking for, let's say, the letter, I in a word and let's say it's in.
Hi, my name is Ian.
If I click, run.
I get true because the letter I.
Does exist in this drink.
All right, let's learn another one.
Another one is basket dot count.
And we can count how many times an item occurs, so, for example, if I do D and I click run.
I get one because D only exists once in the list, but if I add another D in here and I click run.
We get to it counts how many time this value occurs in our list, a very, very useful.
All right, a few more still to go.
Let's do some exercises and I'll see you in the next one.