1 00:00:00,270 --> 00:00:01,140 Welcome back. 2 00:00:01,170 --> 00:00:04,019 Let's keep going with some more string methods. 3 00:00:04,260 --> 00:00:06,660 Now we've learned about adding and removing ones. 4 00:00:06,660 --> 00:00:09,650 We learned about append, insert and extend. 5 00:00:09,660 --> 00:00:13,650 And then in removing, we learned about pop, remove and clear. 6 00:00:14,070 --> 00:00:15,840 There's a few other important ones. 7 00:00:16,640 --> 00:00:19,100 Let's go with the index. 8 00:00:20,160 --> 00:00:23,280 So instead of clearing here, let's clean this up. 9 00:00:24,950 --> 00:00:28,760 And we'll do basket dot. 10 00:00:29,550 --> 00:00:30,300 Index. 11 00:00:31,310 --> 00:00:32,540 An index. 12 00:00:32,960 --> 00:00:36,380 As you can see, we give it a value, a start and a stop. 13 00:00:36,650 --> 00:00:37,610 What does that mean? 14 00:00:37,700 --> 00:00:42,590 Well, we want to say, hey, what index is number two? 15 00:00:43,970 --> 00:00:47,120 If we do index of two and I click run. 16 00:00:48,630 --> 00:00:50,070 It's going to give me one. 17 00:00:50,070 --> 00:00:54,170 I know this is a little confusing, but it's asking for the index. 18 00:00:54,180 --> 00:00:55,790 Where is number two? 19 00:00:55,800 --> 00:00:58,470 Number two is at index of one. 20 00:00:58,770 --> 00:01:02,190 Let's change these into letters just so it's more clear. 21 00:01:02,190 --> 00:01:03,750 So we have a B. 22 00:01:04,629 --> 00:01:05,319 See. 23 00:01:06,470 --> 00:01:07,150 D. 24 00:01:07,160 --> 00:01:09,050 And then finally, E. 25 00:01:10,290 --> 00:01:11,940 And again, if I do. 26 00:01:12,910 --> 00:01:14,620 D here and I click Run. 27 00:01:15,510 --> 00:01:21,870 I get an index of three because zero one, two, three, it's on shelf three in our memory. 28 00:01:22,470 --> 00:01:29,310 And you can also do a optional parameter here, which is where should we start looking? 29 00:01:29,310 --> 00:01:35,640 So I want you to start looking at index of zero and then finish looking at index of two. 30 00:01:36,060 --> 00:01:38,850 If I do run here, I get an error. 31 00:01:38,850 --> 00:01:45,570 It says, hey de is not in list because well, we started at index of zero and stopped an index of two. 32 00:01:45,750 --> 00:01:48,060 If I do three and I click Run. 33 00:01:48,870 --> 00:01:51,510 No, it stops right before three. 34 00:01:51,510 --> 00:01:53,160 So if I do four. 35 00:01:54,500 --> 00:01:55,490 And I click Run. 36 00:01:56,720 --> 00:01:57,360 There you go. 37 00:01:57,380 --> 00:01:58,580 I get three. 38 00:01:59,520 --> 00:02:00,210 Now. 39 00:02:00,390 --> 00:02:02,400 Errors are not good in our programs. 40 00:02:02,400 --> 00:02:07,070 Ideally, we don't want to get errors, so how can we avoid this? 41 00:02:07,080 --> 00:02:10,740 What if we're looking for something and we're not sure if it's in the list or not? 42 00:02:11,070 --> 00:02:18,210 There's another nifty way of looking for things in a list, and this involves what we call a python 43 00:02:18,210 --> 00:02:19,140 key word. 44 00:02:19,770 --> 00:02:25,200 A key word is something that you use in Python that well already has some meaning. 45 00:02:26,350 --> 00:02:30,170 For example, a key word here if I go to Python. 46 00:02:30,190 --> 00:02:34,840 Key words are all these words that already mean something. 47 00:02:34,870 --> 00:02:41,290 Now we're going to go through them, and we haven't seen a lot of them yet, but we might have seen 48 00:02:41,290 --> 00:02:44,590 true right in boolean values to mean something. 49 00:02:44,590 --> 00:02:51,460 So in Python we can't really use the word true because well, it already means something. 50 00:02:52,290 --> 00:02:59,610 There's a word called in that, as you can see, as soon as we type mean something is a key word in 51 00:02:59,610 --> 00:03:09,510 python and this is quite nice we can say hey is DX in basket and if I run this. 52 00:03:10,590 --> 00:03:15,150 I get true OC is ex and basket. 53 00:03:16,750 --> 00:03:21,790 I get false because, well, it doesn't exist. 54 00:03:22,240 --> 00:03:24,190 And this is actually quite useful. 55 00:03:24,190 --> 00:03:26,340 And we can even do it for strings. 56 00:03:26,350 --> 00:03:34,480 For example, if I'm looking for, let's say, the letter I in a word and let's say it's I in. 57 00:03:34,720 --> 00:03:38,680 Hi, my name is Ian. 58 00:03:39,510 --> 00:03:40,890 If I click Run. 59 00:03:42,020 --> 00:03:45,020 I get true because the letter I. 60 00:03:45,050 --> 00:03:46,700 Does exist in this string. 61 00:03:47,210 --> 00:03:49,120 All right, let's learn another one. 62 00:03:49,130 --> 00:03:52,760 Another one is basket dot count. 63 00:03:54,020 --> 00:03:57,440 And we can count how many times an item occurs. 64 00:03:57,470 --> 00:04:01,460 So, for example, if I do, DH and I click Run. 65 00:04:02,230 --> 00:04:07,240 I get one because DD only exists once in the list. 66 00:04:07,240 --> 00:04:10,750 But if I add another DH in here and I click run. 67 00:04:11,590 --> 00:04:12,660 We get to. 68 00:04:12,670 --> 00:04:17,019 It counts how many times this value occurs in our list? 69 00:04:17,050 --> 00:04:18,579 Very, very useful. 70 00:04:19,180 --> 00:04:19,740 All right. 71 00:04:19,750 --> 00:04:21,209 A few more still to go. 72 00:04:21,220 --> 00:04:24,040 Let's do some exercises and I'll see you in the next one.