1 00:00:00,510 --> 00:00:04,890 We can access a wide range of characters using slicing 2 00:00:07,710 --> 00:00:11,550 if we want to cut a substring from a string. 3 00:00:11,550 --> 00:00:14,320 This is known as String slicing. 4 00:00:14,430 --> 00:00:23,890 We can access a range of items in a string by using the slicing operator colon and this is how the syntax 5 00:00:23,890 --> 00:00:24,460 was like. 6 00:00:24,460 --> 00:00:36,120 Thing looks like say for example I want to retrieve the characters you in the from these string country. 7 00:00:36,190 --> 00:00:45,640 This is how we construct the slice the first index number is where these lines start. 8 00:00:45,790 --> 00:00:53,680 So we want to begin the slicing at the character you which is inclusive. 9 00:00:54,070 --> 00:01:00,550 And the second index numbered is where these lies and exclusive. 10 00:01:00,580 --> 00:01:08,190 So when I say the second index number is 6 these lighting stops here 11 00:01:11,150 --> 00:01:14,350 and it is going to exclude the character. 12 00:01:14,350 --> 00:01:14,620 Why. 13 00:01:14,630 --> 00:01:17,830 That is the index number 6. 14 00:01:17,990 --> 00:01:26,570 So the output would be you in T. 15 00:01:29,860 --> 00:01:34,860 Let's check these lighting functionality in the Jupiter non book. 16 00:01:35,050 --> 00:01:42,730 Let's define a string and like we discussed we will 17 00:01:45,970 --> 00:01:55,000 we will slice the string from the index to up to index six exclusive. 18 00:01:55,100 --> 00:02:10,270 So as you can see here the original string is d r 1 has been sliced from index to 2 to index 6 excluding 19 00:02:11,940 --> 00:02:12,300 now. 20 00:02:12,300 --> 00:02:20,010 Say for example I would want to retrieve all of the characters in the string then I could give something 21 00:02:20,010 --> 00:02:21,690 like this. 22 00:02:21,690 --> 00:02:29,490 If we remove both of the indexes and include the colon in between these great brackets this would retrieve 23 00:02:29,520 --> 00:02:31,520 all of the characters in this string. 24 00:02:32,580 --> 00:02:39,960 So this would give me on the characters. 25 00:02:40,150 --> 00:02:54,320 Now if I want to retrieve say for example characters up onto index code that gives I can leave the first 26 00:02:54,440 --> 00:03:13,840 index as blank or Z2 and then the output would be C or U N because this exclude the index numbered form 27 00:03:14,190 --> 00:03:27,820 which is d next if I want to retrieve the characters beginning from the card index number. 28 00:03:27,830 --> 00:03:37,100 In that case I can give the first index as 2D and leave the second index as blank. 29 00:03:37,100 --> 00:03:44,160 This would give me t y. 30 00:03:44,460 --> 00:03:49,560 So let me see this in the in the Jupiter note book. 31 00:03:51,770 --> 00:04:01,060 So in order to retrieve all of the characters in this string within the square brackets I include the 32 00:04:01,060 --> 00:04:15,280 colon that the paused and the second index numbers as blank so this retrieves all the characters. 33 00:04:15,280 --> 00:04:17,600 Now save for example exam. 34 00:04:23,510 --> 00:04:29,280 I want to retrieve all of the characters beginning from the index. 35 00:04:29,390 --> 00:04:30,380 Three. 36 00:04:30,840 --> 00:04:46,720 So I would give you the index three here as the first index number and leave out the second index number. 37 00:04:49,770 --> 00:05:00,140 So slicing begins with the index number three and retrieves all of the characters until the end of the 38 00:05:00,140 --> 00:05:01,900 string. 39 00:05:01,900 --> 00:05:16,660 Say now I want to retrieve the characters beginning from the zero 8 index up until the index by so nutcase 40 00:05:18,750 --> 00:05:29,400 I am going to leave out the first index number and enter the second index number six and instead of 41 00:05:29,410 --> 00:05:33,330 four leaving the first index number as blank. 42 00:05:33,390 --> 00:05:41,440 You can also enter zero meaning you're on to the tree beginning from the zero it index. 43 00:05:41,610 --> 00:05:44,690 So the result remained the same. 44 00:05:44,700 --> 00:05:49,180 Another feature of slicing is extended slicing. 45 00:05:49,320 --> 00:05:59,400 Say for example I would like to retrieve every other character the index number zero up until the index 46 00:05:59,400 --> 00:06:00,360 number five. 47 00:06:01,230 --> 00:06:04,230 So I want to retrieve the characters see 48 00:06:07,170 --> 00:06:09,100 and deep. 49 00:06:09,250 --> 00:06:17,530 So how do we do that and this is this index for the extended slice. 50 00:06:17,620 --> 00:06:25,310 The first index numbered repos to where the slicing begins. 51 00:06:25,460 --> 00:06:38,020 The second index number refers to where the slicing ends and deterred but amateur hood is known as a 52 00:06:38,020 --> 00:06:39,030 straight. 53 00:06:39,070 --> 00:06:46,550 And this refers to how many characters to move forward after the first character is retrieved from the 54 00:06:46,550 --> 00:06:47,540 string. 55 00:06:47,560 --> 00:06:55,840 So in either case we are going to retrieve every other character every second character from the first 56 00:06:56,140 --> 00:06:56,770 character. 57 00:06:58,000 --> 00:07:07,820 This would give me the output as I see you deep by default the. 58 00:07:07,850 --> 00:07:19,000 Is this parameter would be 1 which means it retrieves all of the characters beginning from 0 with index. 59 00:07:19,000 --> 00:07:25,980 Let's go see how the extended slice works in the Jupiter known book. 60 00:07:26,050 --> 00:07:28,290 So this is a string. 61 00:07:28,360 --> 00:07:29,470 String 1. 62 00:07:30,280 --> 00:07:39,160 And I'm going to begin the slicing from index 0 so begins things. 63 00:07:39,180 --> 00:07:40,710 It is index 0. 64 00:07:40,710 --> 00:07:44,270 You can either enter 0 or leave it as a blank. 65 00:07:44,550 --> 00:08:00,510 The second index number is 5 so these lighting and add 5 character play and the third parameter to this 66 00:08:00,510 --> 00:08:07,350 trait parameter and we are going to enter 2 which means we are going to retrieve every other character. 67 00:08:08,570 --> 00:08:10,750 So executing. 68 00:08:10,880 --> 00:08:12,860 So this is the output. 69 00:08:12,860 --> 00:08:15,990 Let us see. 70 00:08:16,110 --> 00:08:20,040 I want to retrieve all of the characters between 0 and 5. 71 00:08:21,070 --> 00:08:32,100 And I'm going to enter these tried but amateur as one execute so it doesn't read all of the characters. 72 00:08:32,120 --> 00:08:46,400 Now let us skip over these trade parameters so enter your first and second index numbers so the output 73 00:08:46,460 --> 00:08:48,390 is the same as this. 74 00:08:48,410 --> 00:08:51,620 Then this trade parameter has been given as one. 75 00:08:51,650 --> 00:08:59,780 This means Python defaults to these tried of one so that every character between the two index numbers 76 00:08:59,870 --> 00:09:00,640 is retrieved. 77 00:09:01,760 --> 00:09:03,170 This is about slicing.