Welcome back.
Let's keep going with some more stirring methods.
Now we've learned about adding and removing once we learned about a penned insert an extent and then
a 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 index
and 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 1.
Let's change these into letters just so it's more clear.
So we have a b c d.
And then finally e and again if I do D here and I click Run I get an index of 3 because 0 1 2 3.
It's on shelf 3 in our memory.
And you can also do a optional parameter here which is where shall we start looking.
So I want you to start looking at index of 0 and then finish looking at index of 2.
If I do run here I get an error.
It says hey D is not in List because while we started at index of 0 and stopped it index of 2 if I do
three and I click Run No it stops right before three.
So if I do four and I click Run there yo I get three now errors are not good or 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 that 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 keyword here if I go to Python keywords are all these wars that already mean something.
Now we're gonna 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 is a word called in that as you can see as soon as we type means something as a keyword in Python.
And this is quite nice.
We can say hey is D in the basket and if I run this I get true okay is X in basket 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 I in.
Hi my name is Ian if I click Run I get true because the letter I does exist in this string.
All right well 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 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.