1 00:00:00,000 --> 00:00:01,700 [no audio] 2 00:00:01,710 --> 00:00:02,700 Friends here 3 00:00:02,700 --> 00:00:06,800 we are going to discuss two more very, very important string 4 00:00:06,800 --> 00:00:08,600 operations in your real time. 5 00:00:08,700 --> 00:00:10,800 They are like 'strip' and 'split'. 6 00:00:11,600 --> 00:00:12,800 So to explain this 7 00:00:12,800 --> 00:00:17,500 let me open our first of all command line, then let me enter 8 00:00:17,500 --> 00:00:19,200 into my Python command line. 9 00:00:20,000 --> 00:00:22,200 Let's say I have a string called 10 00:00:22,000 --> 00:00:24,300 New Text 11 00:00:24,300 --> 00:00:28,700 "Python", okay. Then let me simply print your 'x', 12 00:00:28,700 --> 00:00:30,700 [no audio] 13 00:00:30,700 --> 00:00:32,799 and by mistake instead of defining in this way 14 00:00:32,799 --> 00:00:34,400 I have given some " python", 15 00:00:35,700 --> 00:00:39,200 unnecessarily I provide a space before starting your string, 16 00:00:39,400 --> 00:00:42,800 and that space is preserving even while printing your output. 17 00:00:42,900 --> 00:00:47,500 But while printing if there is any space, maybe at starting 18 00:00:47,500 --> 00:00:50,400 side of your given string, or at the ending side of your given 19 00:00:50,400 --> 00:00:54,600 string, like unwantedly I provide that, or by mistake 20 00:00:54,600 --> 00:00:55,700 I have given that space. 21 00:00:55,700 --> 00:00:59,600 I want to remove that in case if there is a space either 22 00:00:59,600 --> 00:01:02,400 side of your given string, I mean towards left side 23 00:01:02,400 --> 00:01:03,600 and towards right side. 24 00:01:04,700 --> 00:01:08,300 See that. First observe that. You're getting your space here 25 00:01:08,300 --> 00:01:09,600 and here, right. Now 26 00:01:09,600 --> 00:01:12,200 let me do 'x.strip'. 27 00:01:13,600 --> 00:01:15,900 Now see the output. You don't have any space on the output side. 28 00:01:17,400 --> 00:01:21,900 So 'x.strip' will remove by default if there is any space 29 00:01:21,900 --> 00:01:25,900 towards left, or towards right side, or extreme sides. Only 30 00:01:26,200 --> 00:01:30,600 starting or at the ending, that space we'll remove by your 31 00:01:30,600 --> 00:01:34,200 'strip' operation. Actually by default 'strip' will remove the 32 00:01:34,200 --> 00:01:37,800 space but I want to remove something like, let's say I have 33 00:01:37,800 --> 00:01:42,900 a string now called in this way, "python". Now, I want to remove 34 00:01:43,200 --> 00:01:45,100 letter "p" or letter "n" 35 00:01:46,000 --> 00:01:49,300 from your given string. Because "p" is there at the starting 36 00:01:49,300 --> 00:01:52,900 side I want to remove that "p", then I can do 'x.strip'. 37 00:01:52,900 --> 00:01:56,400 [no audio] 38 00:01:56,400 --> 00:02:00,800 See that. "p" is removing. Or I want to remove "n". Now see that 39 00:02:00,800 --> 00:02:04,200 "n" is removing. But if I want to remove something called "t", 40 00:02:04,800 --> 00:02:08,800 it won't do because "t" is not there either at starting side 41 00:02:08,900 --> 00:02:09,900 or at ending side. 42 00:02:10,400 --> 00:02:14,600 So if any character or word, if it is there either at starting 43 00:02:14,600 --> 00:02:17,800 side or at ending side of your given string then that will 44 00:02:17,800 --> 00:02:22,700 remove. Let's say I'm going to take "python scripting is easy". 45 00:02:23,700 --> 00:02:27,900 Now what I want to do is I want to remove "easy", then 46 00:02:27,900 --> 00:02:34,900 'x.strip'. If "easy" is there either at starting side or at ending 47 00:02:34,900 --> 00:02:36,100 side then that will remove. 48 00:02:36,100 --> 00:02:37,100 Yes, it is removing. 49 00:02:37,100 --> 00:02:39,300 [no audio] 50 00:02:39,300 --> 00:02:44,200 Right. Now suppose if you are given string is in this way. 51 00:02:45,700 --> 00:02:49,500 Now I want to remove "python" only towards right side, not at 52 00:02:49,500 --> 00:02:52,200 the starting side. This "python" 53 00:02:52,200 --> 00:02:54,600 I don't want to remove. I want to remove only this "python", 54 00:02:54,600 --> 00:02:56,000 this is at right side, right? 55 00:02:56,400 --> 00:03:00,400 So that's why what you have to do is simply 'print(x.strip, 56 00:03:01,800 --> 00:03:06,800 'rightstrip', 'rstrip', remove "python". See the output. 57 00:03:07,200 --> 00:03:11,800 It is removed. It is removing only at right side. If I remove and if I play 58 00:03:11,800 --> 00:03:14,500 simply 'strip' operation it is going to remove your "python" 59 00:03:14,500 --> 00:03:15,500 both the sides. 60 00:03:17,000 --> 00:03:21,100 So same way you can remove your particular word 61 00:03:21,100 --> 00:03:23,800 even at left side also by doing 'lstrip'. 62 00:03:24,900 --> 00:03:30,300 So 'strip', 'lstrip', 'rstrip'. Right. Fine. 63 00:03:30,400 --> 00:03:33,000 Now, let's say I have a string called 64 00:03:34,100 --> 00:03:38,500 "python", something in this way. Okay. 65 00:03:38,500 --> 00:03:44,300 Now I want to remove "./i". Directly I can do it 'x.strip'. 66 00:03:45,800 --> 00:03:48,300 So that result I want to store into 'x' itself, suppose 67 00:03:48,300 --> 00:03:50,000 'x = x.strip'. 68 00:03:50,800 --> 00:03:55,000 I want to remove './i', If anything is there either 69 00:03:55,000 --> 00:03:58,600 at starting side or at ending side, and that result again 70 00:03:58,600 --> 00:04:01,000 I stored into my 'x'. See that. 71 00:04:01,000 --> 00:04:03,400 [no audio] 72 00:04:03,400 --> 00:04:06,300 And let's say I have in this way string "python". 73 00:04:06,300 --> 00:04:08,100 [no audio] 74 00:04:08,100 --> 00:04:09,100 Okay. 75 00:04:10,100 --> 00:04:11,900 Now something called 76 00:04:13,200 --> 00:04:14,200 "yy" 77 00:04:14,200 --> 00:04:16,200 [no audio] 78 00:04:16,200 --> 00:04:21,700 So I want to remove letter "p" and "y" in sequence. 79 00:04:22,100 --> 00:04:26,100 I mean, first I can do 'x.strip', because of this you are 80 00:04:26,100 --> 00:04:30,100 going to remove "p", and again on the same operation 81 00:04:30,100 --> 00:04:32,900 I can do one more '.' operation, that is "y". 82 00:04:34,200 --> 00:04:35,200 See that. 83 00:04:36,800 --> 00:04:40,200 So I mean multiple times you can apply '.strip' 84 00:04:40,600 --> 00:04:42,600 operation or combination of 85 00:04:42,600 --> 00:04:44,500 [no audio] 86 00:04:44,500 --> 00:04:48,900 'strip' and 'rstrip' or even 'lstrip' 87 00:04:48,900 --> 00:04:49,900 also you can apply. 88 00:04:51,600 --> 00:04:54,300 Likewise you can do any number of times '.strip', '.strip', 89 00:04:54,800 --> 00:04:56,200 okay, based on requirement. 90 00:04:56,700 --> 00:04:59,400 You just try to remember the functionality of the '.strip' 91 00:04:59,400 --> 00:05:00,800 operation on your given string. 92 00:05:01,000 --> 00:05:03,700 Okay. While writing our real-time scripts there we will see 93 00:05:03,700 --> 00:05:06,000 how to use effectively this 'strip' operation. 94 00:05:07,400 --> 00:05:10,100 Now, let me go with the next operation, 95 00:05:10,100 --> 00:05:13,100 [no audio] 96 00:05:13,100 --> 00:05:14,100 that is 'split'. 97 00:05:14,100 --> 00:05:16,600 So if I do simply 'x.split'. See the output. 98 00:05:16,600 --> 00:05:18,400 [no audio] 99 00:05:18,400 --> 00:05:21,700 Wherever space is there, right, there 100 00:05:21,700 --> 00:05:23,500 it is splitting your given string. 101 00:05:23,800 --> 00:05:25,900 So two places you have a space, 102 00:05:25,900 --> 00:05:28,800 that's why the given string is getting into three parts. 103 00:05:28,800 --> 00:05:30,800 First part, second part, third part. 104 00:05:30,800 --> 00:05:33,200 [no audio] 105 00:05:33,200 --> 00:05:35,800 Right. Actually, this format is called a 'list'. 106 00:05:36,700 --> 00:05:40,000 We have a data structure called 'list' there we'll discuss in 107 00:05:40,000 --> 00:05:42,800 depth with 'list' operations. 108 00:05:42,800 --> 00:05:46,600 As of now just observe 'x.split' will give you a 'list' 109 00:05:46,600 --> 00:05:51,500 output. And how it is going to split? Based on space by default. 110 00:05:51,700 --> 00:05:55,400 But I want to split a given string where a word called 111 00:05:55,400 --> 00:05:59,500 "is" is there. Now see the output. Wherever "is" is there, there 112 00:05:59,500 --> 00:06:03,200 it is going to split. Now as of now you have only one "is" that is why 113 00:06:03,200 --> 00:06:06,200 this is one part, and this is one part. You are getting two parts - 114 00:06:06,700 --> 00:06:08,200 first part, second part. 115 00:06:08,800 --> 00:06:16,300 Let's say your 'x' is in this way, "and it is very popular". 116 00:06:17,700 --> 00:06:21,900 Now in this case if I split with "is" you have "is" 117 00:06:21,900 --> 00:06:26,300 here and here, so two places you have. You will get three parts - 118 00:06:26,300 --> 00:06:30,800 first part, second part, third part. You're going to get a list 119 00:06:30,800 --> 00:06:33,000 which consists of three values. See the output. 120 00:06:34,000 --> 00:06:37,000 first value, second value, and then third value? 121 00:06:37,800 --> 00:06:39,000 Right. So guys 122 00:06:39,000 --> 00:06:42,500 these are the very, very important operations in your real-time - 123 00:06:42,800 --> 00:06:45,000 'strip' and 'split'. Okay. 124 00:06:45,900 --> 00:06:47,800 Okay guys, thank you for watching this video. 125 00:06:47,800 --> 00:06:54,400 [no audio]