1 00:00:00,000 --> 00:00:02,100 [no audio] 2 00:00:02,110 --> 00:00:03,200 Friends here 3 00:00:03,200 --> 00:00:07,200 we are going to see three more different operations on your 4 00:00:07,200 --> 00:00:08,300 given string. 5 00:00:08,600 --> 00:00:12,100 They are like 'count', 'index', and 'find' operations. 6 00:00:13,100 --> 00:00:16,500 See now you can easily understand 'count' operation. 'count' 7 00:00:16,500 --> 00:00:18,400 is nothing but just so you know that you're having some 8 00:00:18,400 --> 00:00:21,200 string in that given string a particular character, 9 00:00:22,400 --> 00:00:26,400 how many times it is appearing in a given string, for that 10 00:00:26,400 --> 00:00:27,800 you're using 'count' operation. 11 00:00:28,500 --> 00:00:30,400 Let me open my terminal here 12 00:00:30,400 --> 00:00:33,700 also, I mean Python Shell, Python command line. 13 00:00:34,100 --> 00:00:44,400 Let's say x = "python is easy and it is popular language" 14 00:00:45,400 --> 00:00:47,800 'x.count'. Right. 15 00:00:47,900 --> 00:00:50,900 I'm going to count how many times letter, sorry word 16 00:00:51,000 --> 00:00:55,600 "is" is there, or I am going to count only particular character. 17 00:00:55,600 --> 00:00:56,800 No problem, you can check it. 18 00:00:56,800 --> 00:00:58,800 [no audio] 19 00:00:58,800 --> 00:01:03,500 Right. Or you can check "t", or you can check letter "a". 20 00:01:04,700 --> 00:01:08,000 Right. You can check particular character or some word also. 21 00:01:08,000 --> 00:01:10,100 Let's say I am going to check. 22 00:01:10,100 --> 00:01:13,000 [no audio] 23 00:01:13,000 --> 00:01:14,300 "easy", anyway "easy" 24 00:01:14,300 --> 00:01:18,000 word is there only one time, so how many times that particular 25 00:01:18,000 --> 00:01:21,500 word or character is appearing in a given string, to count 26 00:01:21,500 --> 00:01:27,800 that you are using 'count' operation, right. Now 'x.index', 27 00:01:28,400 --> 00:01:29,600 this is next operation. 28 00:01:30,000 --> 00:01:33,200 Let's say I want to find the index of letter "p". 29 00:01:35,600 --> 00:01:36,600 See very first 30 00:01:36,600 --> 00:01:39,700 letter "p" is there, very first character "p" is there, we know 31 00:01:40,100 --> 00:01:42,700 whenever you assign string in this way, we have positive 32 00:01:42,700 --> 00:01:45,400 indexes as well as negative indexes. If we count with the 33 00:01:45,400 --> 00:01:47,400 positive, letter "p" is at 0, 34 00:01:48,600 --> 00:01:53,000 but at the same time somewhere you have "p", here and here, but 35 00:01:53,600 --> 00:01:56,900 your 'index' will give by default, whatever the 'index' operation 36 00:01:56,900 --> 00:02:00,600 you have on a given string that will look from left to right, 37 00:02:01,400 --> 00:02:04,900 and very first wherever you are getting "p" that index it will 38 00:02:04,900 --> 00:02:09,600 give. But in case if you want to look from particular position, 39 00:02:09,600 --> 00:02:14,000 I want to look from index 1. That means you are skipping index 40 00:02:14,000 --> 00:02:16,700 0. You are not searching from index 0. You're searching 41 00:02:16,700 --> 00:02:22,600 from index 1 to last. Yes, from there 25th you have. Now instead of 42 00:02:22,600 --> 00:02:27,800 25th I am looking from 26, then 27 we have one more "p" letter. 43 00:02:29,200 --> 00:02:30,700 After that do we have anything? 44 00:02:30,700 --> 00:02:32,900 Let's say I am searching from 28. 45 00:02:33,300 --> 00:02:38,000 You don't have that string in a given, after 28th index 46 00:02:38,200 --> 00:02:39,400 that's why I'm getting an error. 47 00:02:40,600 --> 00:02:48,100 Right. Not only that you can check with like "is". So let 48 00:02:48,100 --> 00:02:51,300 me check with from starting, yes somewhere in 7th index 49 00:02:52,100 --> 00:02:53,400 "is" word is starting. 50 00:02:54,800 --> 00:02:59,300 "i", index is 7. But if you try to look after some particular 51 00:02:59,300 --> 00:03:03,200 index, I want to look from 23, after 23rd index 52 00:03:03,200 --> 00:03:04,200 you don't have "is" word 53 00:03:04,200 --> 00:03:05,200 that's why it is giving an error. 54 00:03:05,500 --> 00:03:09,800 That's why you know if particular thing is there in a given string 55 00:03:10,700 --> 00:03:13,500 you can go and search with 'index' to get the index value of 56 00:03:13,500 --> 00:03:14,400 your given string. 57 00:03:15,000 --> 00:03:18,400 But anyway 'index' operation is sometimes you know, it is giving 58 00:03:18,400 --> 00:03:19,600 bad result in this way. 59 00:03:19,600 --> 00:03:21,900 [no audio] 60 00:03:21,900 --> 00:03:28,800 Right. So what I can do is 'x.find', suppose I am doing "is", or 61 00:03:28,800 --> 00:03:30,900 let's say only single character "p", 62 00:03:30,900 --> 00:03:33,800 [no audio] 63 00:03:33,800 --> 00:03:38,600 I want to look from second index, yes somewhere 25th. 64 00:03:38,900 --> 00:03:40,700 I want to look from 26th 65 00:03:40,700 --> 00:03:42,500 index, yes somewhere 27, 66 00:03:43,100 --> 00:03:47,000 I mean "p" letter is there zeroth position, 25th position, 27th 67 00:03:47,000 --> 00:03:49,300 position. I want to look from 28th. 68 00:03:50,100 --> 00:03:52,600 We are getting -1 means, now after 28th 69 00:03:52,600 --> 00:03:56,400 you don't have any "p" letter in a given string. See compared 70 00:03:56,400 --> 00:03:58,000 to 'index', right, 71 00:03:58,300 --> 00:04:00,500 you can simply forget about your 'index' operation, 72 00:04:01,100 --> 00:04:04,700 just better to remember only 'find' operation. Of course, you have 73 00:04:04,700 --> 00:04:08,500 both the things but it's better to remember 'find' operation 74 00:04:08,500 --> 00:04:11,900 to find index of your particular string, or a character. 75 00:04:12,600 --> 00:04:17,700 So how 'find' is going to work? If that particular character 76 00:04:17,700 --> 00:04:22,399 or word is there it will give the index of that, or it will give -1 77 00:04:23,600 --> 00:04:27,700 if it is not there. Suppose after 28th index, from 28th 78 00:04:27,700 --> 00:04:30,900 index up to last you don't have any "p" letter, "p" character 79 00:04:30,900 --> 00:04:34,400 in a given string that's why it is giving -1. Now if this 80 00:04:34,400 --> 00:04:38,600 result is -1, then you can say that this particular string, 81 00:04:38,600 --> 00:04:42,500 this particular character is not present from 28th to last 82 00:04:42,500 --> 00:04:47,200 index, or some so and so index to last. Let's say in entire string 83 00:04:47,200 --> 00:04:51,100 I'm looking for letter called "z", or string character called 84 00:04:51,100 --> 00:04:53,300 "z". You don't have "z" in the given string, 85 00:04:53,500 --> 00:04:56,700 because your string is like 'x' you don't have any where 86 00:04:56,700 --> 00:04:57,800 "z" in this string, 87 00:04:58,700 --> 00:05:01,200 that's why 'x.find' will give -1. 88 00:05:02,400 --> 00:05:07,000 Right. So guys this 'find' is very, very helpful in your real 89 00:05:07,000 --> 00:05:09,400 time. Instead of 'count', 90 00:05:09,900 --> 00:05:13,400 right, of course 'count' is also useful but 'find' is very, very 91 00:05:13,400 --> 00:05:17,800 useful. Let's say simply give me one example, I am trying 92 00:05:17,800 --> 00:05:22,300 to find Java version through my Python script, right? 93 00:05:22,700 --> 00:05:26,700 So you got some output, something like "java version", 94 00:05:26,700 --> 00:05:30,500 some 1.6, something like that, right. First, what I will do 95 00:05:30,500 --> 00:05:35,600 is your 'java_version.find'. First of all, I 96 00:05:35,600 --> 00:05:37,800 will check whether 'Java' is there or not in a given string. 97 00:05:37,800 --> 00:05:41,100 If it is there I will get some non-zero value, 98 00:05:41,400 --> 00:05:46,100 I mean a positive index value. Then I can say that yes, successfully 99 00:05:46,100 --> 00:05:49,000 I found Java and some Java version is there in the variable 100 00:05:49,000 --> 00:05:50,100 called 'java_version'. 101 00:05:50,700 --> 00:05:57,000 Let's say I got an output like while finding my Java version 102 00:05:57,700 --> 00:05:59,200 "Error while finding". 103 00:05:59,200 --> 00:06:02,100 [no audio] 104 00:06:02,100 --> 00:06:04,900 Now if I try to look 'Java' in the 'java_version' 105 00:06:04,900 --> 00:06:08,000 variable, you don't have. That means you are unable 106 00:06:08,000 --> 00:06:10,800 to find your Java version with the help of your logic. 107 00:06:10,800 --> 00:06:12,100 Somewhere something is wrong. 108 00:06:13,800 --> 00:06:18,100 Right. So to take some decision this value will be helpful. 109 00:06:18,700 --> 00:06:22,200 Okay. So just remember guys how to use 'find', and how it is going 110 00:06:22,200 --> 00:06:25,700 to work. While writing our scripts we will use this so that 111 00:06:25,700 --> 00:06:28,800 you will be clear how to use 'find' operation. 112 00:06:29,300 --> 00:06:33,200 Okay. So this is very, very important in your real time. 113 00:06:33,200 --> 00:06:35,600 [no audio] 114 00:06:35,600 --> 00:06:37,700 Okay guys, thank you for watching this video. 115 00:06:37,700 --> 00:06:45,000 [no audio]