0:00:00.490,0:00:03.090 So I want to introduce one more operation on strings, which 0:00:03.090,0:00:05.930 we'll find very useful, which is the Find operation. It gives 0:00:05.930,0:00:08.980 us the way in a big string to find some sub-string 0:00:08.980,0:00:12.770 that we're looking for. The way we use Find is a little 0:00:12.770,0:00:15.910 different from the way we've used other operators so far. Because 0:00:15.910,0:00:18.320 Find is actually a method, and what that means is it's 0:00:18.320,0:00:21.430 a built in procedure provided by Python. We'll be able to 0:00:21.430,0:00:25.860 define our own procedures soon, we'll get to that in unit two. 0:00:25.860,0:00:29.630 Find is a procedure that operates on strings, so we use it by having 0:00:29.630,0:00:32.189 a string followed by .find, followed by 0:00:32.189,0:00:34.500 a parentheses, then we pass in another string. 0:00:36.570,0:00:38.700 Which is the string that we want to find in 0:00:38.700,0:00:41.330 the first string. And the output of Find is the 0:00:41.330,0:00:46.550 position in the string where that sub-string is found, the 0:00:46.550,0:00:49.720 first occurrence of the string. So, if that string happens 0:00:49.720,0:00:52.290 to occur in more places than one in the 0:00:52.290,0:00:54.380 input string, the result of find is always going to give 0:00:54.380,0:00:57.900 us the position. That's the number where the first occurrence 0:00:57.900,0:01:01.630 of the sub-string occurs. So the output of using Find 0:01:01.630,0:01:04.060 will be the first position in the search string, which 0:01:04.060,0:01:07.390 is this blue string right here, where the target string, 0:01:07.390,0:01:10.520 which is the purple string, occurs. So that will be 0:01:10.520,0:01:14.200 a number. If the target string is not a found anywhere 0:01:14.200,0:01:16.760 in the search string, then the output would be negative 0:01:16.760,0:01:19.140 1. So let's try a few examples to understand how 0:01:19.140,0:01:21.970 that works and we'll do this in the Python interpreter. 0:01:21.970,0:01:27.210 Here I've initialized the variable Pythagoras to hold the string here 0:01:27.210,0:01:29.360 that's been attributed to Pythagoras. We don't know if 0:01:29.360,0:01:32.190 he really said it. But it says there's a geometry 0:01:32.190,0:01:34.930 in the humming of strings, there is music in 0:01:34.930,0:01:39.100 the spacing of spheres. So now, we have that variable 0:01:39.100,0:01:43.710 initialized, so I'm going to invoke Find, using Pythagoras as 0:01:43.710,0:01:45.970 the string that we're searching in, and that's the value 0:01:45.970,0:01:48.800 that we initialized it to with a string, passing in 0:01:48.800,0:01:52.290 as the search string the string string. When we run 0:01:52.290,0:01:59.450 this, we see that we get 40 as the result. If we counted, this is position 0, we 0:01:59.450,0:02:02.600 would see string starting at position 40. Since I 0:02:02.600,0:02:05.110 don't want to count that far, we can use our indexing 0:02:05.110,0:02:07.560 to see if that's right. So let's print Pythagoras 0:02:09.110,0:02:11.880 starting from index 40, we could print all the 0:02:11.880,0:02:14.980 way to the end using a colon. And, when 0:02:14.980,0:02:17.870 we run that, we see that it starts with string 0:02:17.870,0:02:21.820 which is what we found with the Find. We can search 0:02:21.820,0:02:27.380 for other positions if we search for Pythagoras the single letter T. 0:02:27.380,0:02:30.515 Well that matches the beginning, so we should find the resulted position 0:02:30.515,0:02:34.930 0 which is what we get and we can look for sphere. 0:02:34.930,0:02:38.210 [BLANK_AUDIO] 0:02:38.210,0:02:41.565 That will match sphere at the end. We get 0:02:41.565,0:02:45.410 position 86. Let's print the quote from position 86. And 0:02:48.590,0:02:53.130 we see the end of the quote starting from sphere. [SOUND] 0:02:53.130,0:02:57.470 If we search for a string that's not in the string 0:02:57.470,0:03:00.840 that we're using as the search string, so let's look for 0:03:00.840,0:03:06.770 say, algebra, which was not in the quote from Pythagoras, we 0:03:06.770,0:03:09.800 get the output negative one. That means the string was not found.