1 00:00:00,240 --> 00:00:08,930 This tutorial we will discuss about drawing macaques Python has a set of built in method that we can 2 00:00:08,930 --> 00:00:16,340 use on strings and these methods can be used to manipulate strings. 3 00:00:16,820 --> 00:00:23,850 So we will discuss about some of the metrics before discussing about the method. 4 00:00:24,050 --> 00:00:31,810 I would like to discuss about one important point as we know the strings are immutable. 5 00:00:31,800 --> 00:00:37,180 So North string method can change the original string. 6 00:00:37,200 --> 00:00:45,890 It can only do it on a new string so let us check this using an example. 7 00:00:45,900 --> 00:00:58,240 This is the syntax for calling a method on an object Object dot method open and close parenthesis the 8 00:00:58,270 --> 00:01:08,500 connection between the method with the object is indicated by a dot written between them the dot notation 9 00:01:08,560 --> 00:01:20,420 is used to access the methods so in no case the object would be let's string please don't worry much 10 00:01:20,480 --> 00:01:30,770 about objects and method because I have discussed about objects method functions in detail in another 11 00:01:30,770 --> 00:01:31,780 tutorial. 12 00:01:32,030 --> 00:01:39,760 For now we will understand how each method can be used on the string to manipulate it. 13 00:01:41,240 --> 00:01:48,950 Say for example I would like to change all of the characters in the string to uppercase. 14 00:01:49,010 --> 00:01:57,920 So in that case I can use the method output and if I want to apply this method on the object. 15 00:01:57,970 --> 00:02:04,170 This is the syntax is dot upper open close parenthesis. 16 00:02:04,300 --> 00:02:14,750 So when this particular method is applied on the object that is a string this word can work all of the 17 00:02:14,750 --> 00:02:23,480 characters do with ease let us check this in the Jupiter note book. 18 00:02:23,840 --> 00:02:35,320 So we have a string s which contains this text Halloway and I want to change all of the characters in 19 00:02:35,320 --> 00:02:38,440 this string to uppercase. 20 00:02:38,620 --> 00:02:49,590 So we'll call the method a bird on this string s then execute the cell so all of the characters have 21 00:02:49,590 --> 00:02:52,530 been converted to uppercase. 22 00:02:52,530 --> 00:03:02,270 Similarly we have another method Lowood which converts all of the characters to lowercase so let's execute 23 00:03:02,300 --> 00:03:08,160 this in had a word in lowercase 24 00:03:11,530 --> 00:03:20,520 another method is capitalized which will capitalize capitalizes only the first letter word in the string. 25 00:03:20,520 --> 00:03:24,840 So this is the method capitalize 26 00:03:29,410 --> 00:03:30,100 execute. 27 00:03:31,030 --> 00:03:41,230 So as you can see the word devil you in the origin of string which is in capitals has been changed to 28 00:03:41,230 --> 00:03:50,930 lowercase so we have talked before that strings are immutable and the different methods that are applied 29 00:03:50,930 --> 00:03:54,600 on the object do not change the original string. 30 00:03:54,680 --> 00:04:03,740 Let's display these string s and see if there are any changes to the string as you can see none of the 31 00:04:03,740 --> 00:04:07,670 methods could change the original string. 32 00:04:08,800 --> 00:04:15,460 The next matter that we're going to talk about is count which returns the number of times a specified 33 00:04:15,460 --> 00:04:19,300 value has occurred in this string. 34 00:04:19,450 --> 00:04:32,110 So I want to count the number of times the letter or it occurs in this particular string so as dark 35 00:04:32,170 --> 00:04:39,530 count and in the parent is we give the character at all. 36 00:04:39,650 --> 00:04:42,550 So there are two O's in the string. 37 00:04:43,210 --> 00:04:46,750 And here is the one from the count method. 38 00:04:46,810 --> 00:04:51,030 The next method is is Lowood. 39 00:04:51,190 --> 00:04:59,590 It returns a boolean value if all of the characters in the string are in lowercase so let execute this 40 00:04:59,790 --> 00:05:00,550 cell. 41 00:05:00,790 --> 00:05:03,580 And check point. 42 00:05:03,620 --> 00:05:11,200 That's because the characters in this string are in upper and lower Keys. 43 00:05:11,350 --> 00:05:22,610 If you want to find out the position of a substring in a string you can use the find mentor and independent 44 00:05:22,610 --> 00:05:28,430 voices you enter the substring that you want to find in the string. 45 00:05:28,880 --> 00:05:43,470 So I want to look for an oh so the defined method returns the lowest index where the substring is found. 46 00:05:43,470 --> 00:05:52,830 So in the string is the substring a law is at the third position. 47 00:05:52,940 --> 00:05:53,420 So 48 00:05:56,520 --> 00:05:59,930 the method fine it an integer value. 49 00:06:00,660 --> 00:06:06,040 Let's so line and not this up string. 50 00:06:06,100 --> 00:06:19,450 Let's find the position all the substring or so as you can see it only returned the lowest index or 51 00:06:19,540 --> 00:06:22,470 the substring so it. 52 00:06:22,630 --> 00:06:36,340 It has returned the position or the substring or here which has an index for say for example the substring 53 00:06:36,370 --> 00:06:44,670 that you want to search for in the string is not found by the method line. 54 00:06:44,680 --> 00:06:48,610 In that case it returns of minus 1. 55 00:06:48,610 --> 00:06:56,920 If you want to replace an all substring with a new substring you can use the method replace. 56 00:06:56,920 --> 00:07:00,510 And here you need to specify two parameters. 57 00:07:00,640 --> 00:07:12,670 The first parameter is for the all substring say I want to replace the substring or with the substring 58 00:07:12,970 --> 00:07:19,520 E and then execute this in so very good. 59 00:07:19,550 --> 00:07:21,910 The Interpreter. 60 00:07:21,920 --> 00:07:24,070 Find the substring. 61 00:07:24,080 --> 00:07:27,770 All it is replaced with the substring. 62 00:07:28,100 --> 00:07:36,460 You can check if a string starts with a specified prefix using the start with method. 63 00:07:36,830 --> 00:07:42,350 And this method returns a boolean value which is true or false. 64 00:07:42,380 --> 00:07:56,220 Say for example independent this is I enter I entered H and then execute the C source and the string 65 00:07:56,250 --> 00:07:59,530 Hello World starts with the letter H. 66 00:07:59,550 --> 00:08:00,930 This is true. 67 00:08:00,930 --> 00:08:01,860 Start with 68 00:08:05,040 --> 00:08:10,230 the substring B and it should return flight 69 00:08:13,150 --> 00:08:15,350 next to the index method. 70 00:08:15,370 --> 00:08:22,740 Then this method returns the index or the substring if it is found in a string. 71 00:08:23,970 --> 00:08:25,980 So let us find what the 72 00:08:28,520 --> 00:08:38,320 spewing substring w so it is given an integer value 6. 73 00:08:38,550 --> 00:08:50,180 Let us fine for it and not the substring C M so since m is not in hello world. 74 00:08:50,220 --> 00:08:52,880 It has raised an exception. 75 00:08:53,040 --> 00:08:54,920 Next does the split method. 76 00:08:54,930 --> 00:09:04,500 The split method breaks the string at the separator which is specified in the parenthesis yard and it 77 00:09:04,500 --> 00:09:20,000 returns a list of strings so for example I want to specify separated spaces and then executed using 78 00:09:21,620 --> 00:09:32,150 so the method has split the string into two part one is hello and the board under the split. 79 00:09:32,210 --> 00:09:38,840 Add add these specify a d separator that has been given your which is spaces. 80 00:09:39,350 --> 00:09:50,810 So let us give another separator C I would like to let add the substring separator or so wherever it 81 00:09:50,810 --> 00:10:01,330 finds the separator or it splits the string and then returns the sub strings in a list. 82 00:10:03,110 --> 00:10:14,980 Say for example here I give another word a separate code which is not found in this string that gays 83 00:10:15,430 --> 00:10:22,920 it does not split the string and it returns the string as one single element in the list. 84 00:10:23,080 --> 00:10:33,440 The length method returns the length of the string and it doesn't take any parameters other than the 85 00:10:33,440 --> 00:10:34,700 name of the string. 86 00:10:34,850 --> 00:10:45,790 So independent assess here I I'm going to enter this string s then execute the length method includes 87 00:10:46,090 --> 00:10:56,250 letters called mass spaces be added exclamation marks apostrophe use when calculating the length of 88 00:10:56,250 --> 00:11:00,040 a string. 89 00:11:00,090 --> 00:11:04,280 So this is about the different string method.