00:04
Okay, good day, ladies and gentlemen.
00:07
This is problem number 8 .4 in the python book, and it asked us to implement your own string class, what they call the count method.
00:21
Okay, so what is this after? well, if you're given a string, for example, welcome, and you want to look for the number of ease in welcome.
00:33
So in particular, you want your function, we'll call a count, to return two if it's after the number of e's.
00:44
You know, if we're after the number of, i mean, if we're looking for, then count of w and welcome, of course, would return one here.
01:00
And count of b and welcome, of course, would return zero.
01:11
So in particular, then, we're after the number of certain kinds of letters in the, or whatever the character is.
01:26
So we're after, so we want this, we want count of certain car from some string s, from my string.
01:46
Okay.
01:47
And we want this guy to somehow or another, we want him to count the characters in a string.
01:59
So now what does this mean? so one way to do this is, of course, basically to step through, to iterate through the string and somehow or another count one if the character, so iterate through string and count one if my string.
02:34
Of k in other words the particular position we're at is equal to car and of course to count zero if my string of k is not so you know so in other words it counts one only if it is equal to car in particular so okay.
03:04
So with this in mind, i mean, there's kind of a standard way to do this kind of thing.
03:10
And i think the best way to do it, of course, is to just start off.
03:17
And we'll say, we can just call something counter and we set it equal to zero.
03:24
Now, in python, you don't have to call this a variable or anything.
03:28
It's not like javascript or whatever.
03:30
You can actually, this by saying counter is equal to zero, it defines it as a variable.
03:38
In this case, it's an integer.
03:42
It's zero.
03:44
And you don't have to, you don't actually have to do anything else to it.
03:53
You don't have to declare it as anything unlike some other languages.
03:57
Now, because i want to iterate through the, the, the, the my string, what i was doing is for k in my string.
04:12
So what this statement does, so this statement, what it does is it actually goes through the elements of the string.
04:24
So in particular then, for example, if my string is equal to, we'll just call it a, b, c, d...