1 00:00:00,000 --> 00:00:05,400 [no audio] 2 00:00:05,410 --> 00:00:07,000 Hi friends. Here 3 00:00:07,000 --> 00:00:10,700 we are going to learn some of the string operations, they're 4 00:00:10,700 --> 00:00:12,400 like you know case conversion. 5 00:00:13,100 --> 00:00:16,900 I mean lower to upper, upper to lower, any string into title 6 00:00:16,900 --> 00:00:20,200 format, or making capitalized, something like that. Okay. 7 00:00:20,700 --> 00:00:22,100 Let me open my 8 00:00:22,100 --> 00:00:24,500 [no audio] 9 00:00:24,500 --> 00:00:25,500 Sublime Text Editor. 10 00:00:26,500 --> 00:00:28,700 So guys here I'm going to use, you can use anything, 11 00:00:28,800 --> 00:00:30,600 okay, but I am using Sublime Text Editor here. 12 00:00:30,600 --> 00:00:35,200 Let me first give a name for that by pressing simply 'Ctrl + S', 13 00:00:35,700 --> 00:00:40,100 so 'Desktop', then under our directory 14 00:00:40,100 --> 00:00:44,800 let me create a 'case_conversion_operations'. 15 00:00:44,800 --> 00:00:47,400 [no audio] 16 00:00:47,400 --> 00:00:50,200 on_strings.py'. 17 00:00:50,200 --> 00:00:52,400 [no audio] 18 00:00:52,400 --> 00:00:54,600 That's it. Right. See guys 19 00:00:54,600 --> 00:00:57,100 I am going to define a string called 'my_str', you can take 20 00:00:57,100 --> 00:01:00,500 anything, okay. I'm going to write something like 21 00:01:02,000 --> 00:01:05,900 "python scripting", okay. 22 00:01:06,599 --> 00:01:09,000 Now let me print first our string directly 23 00:01:09,000 --> 00:01:11,600 whatever you have. See the output. 24 00:01:11,900 --> 00:01:14,400 Yes, you are getting. Now guys 25 00:01:14,400 --> 00:01:17,500 I want to convert my entire string into lowercase. 26 00:01:17,900 --> 00:01:22,900 Nothing is there, simply '.lower' operation, on your string '.lower' operation. 27 00:01:24,500 --> 00:01:29,300 Or I want to convert my entire string into uppercase letters. 28 00:01:29,300 --> 00:01:32,200 [no audio] 29 00:01:32,200 --> 00:01:33,200 See the output. 30 00:01:34,300 --> 00:01:36,400 Or after performing these two operations 31 00:01:36,400 --> 00:01:38,000 I want to print my string as well. 32 00:01:38,500 --> 00:01:39,500 See the output. 33 00:01:39,500 --> 00:01:41,500 [no audio] 34 00:01:41,500 --> 00:01:44,500 So here you have to understand one thing, whatever the operations 35 00:01:44,500 --> 00:01:47,700 you are performing on your string with a '.', right, 36 00:01:48,000 --> 00:01:50,600 they don't modify your original string. 37 00:01:50,600 --> 00:01:53,000 That's why because of the third print statement 38 00:01:53,000 --> 00:01:55,500 you are getting your original string Python scripting with 39 00:01:55,500 --> 00:02:00,900 P&S only capital. Even though in second line you are performing 40 00:02:01,000 --> 00:02:05,400 your string '.lower' and third line, right, 41 00:02:05,400 --> 00:02:07,100 you're performing 'upper' 42 00:02:08,000 --> 00:02:10,300 they don't modify your original string. 43 00:02:10,800 --> 00:02:14,300 That's why strings are called 'immutable'. Once if you define 44 00:02:14,300 --> 00:02:18,000 your string you cannot change the part of your string. Already 45 00:02:18,000 --> 00:02:23,000 we know that. Already we have seen that, right. Fine. Suppose if 46 00:02:23,000 --> 00:02:27,500 you want to capture after performing the lowercase letter 47 00:02:27,500 --> 00:02:31,200 or after performing your entire string into 'upper' you can store 48 00:02:31,200 --> 00:02:33,100 this operation result into some variable. 49 00:02:33,100 --> 00:02:38,000 Let's say 'my_str', in lowercase only 'lower'. Any variable 50 00:02:38,000 --> 00:02:40,300 you can take but I am taking this one. That's it. 51 00:02:42,200 --> 00:02:45,200 Right. Now, instead of printing 'my_str.lower', already 52 00:02:45,200 --> 00:02:46,200 we have done 53 00:02:47,300 --> 00:02:50,300 on your variable. We perform 'lower' operation, and we stored 54 00:02:50,300 --> 00:02:53,400 that result into this variable. Now print this variable and 55 00:02:53,400 --> 00:02:54,200 see the output. 56 00:02:54,200 --> 00:02:56,800 [no audio] 57 00:02:56,800 --> 00:03:01,600 Let me comment these two lines and observe your output. Already 58 00:03:01,600 --> 00:03:04,800 we have written, right. See the output. That's it. 59 00:03:05,900 --> 00:03:10,700 Right. So guys as of now we have seen 'lower' and 'upper' operations 60 00:03:10,700 --> 00:03:15,500 on your given string, but how you know how many operations 61 00:03:15,500 --> 00:03:18,400 are there on a given string, right? 62 00:03:18,600 --> 00:03:22,200 See, let me simply open my command line and let me enter into 63 00:03:22,200 --> 00:03:23,300 my Python shell, 64 00:03:24,800 --> 00:03:29,000 simply define any variable called any string, and simply run 65 00:03:29,000 --> 00:03:33,900 'print(dir(X))', so 'dir' is the helping word 66 00:03:33,900 --> 00:03:37,200 for us to list out all the operations which are available 67 00:03:37,200 --> 00:03:41,200 on your given string because here 'X' is a string, because you 68 00:03:41,200 --> 00:03:44,100 can randomly assign some string to some variable 'X', or any 69 00:03:44,100 --> 00:03:48,400 variable, and on that variable if you perform simply 'dir(X)' 70 00:03:48,400 --> 00:03:51,800 it will give the available operations on your given string. 71 00:03:53,100 --> 00:03:56,600 There are so many, right, so I will go with step by step. 72 00:03:58,000 --> 00:04:03,000 So now we have seen this is 'upper' operation, and somewhere you have 73 00:04:03,000 --> 00:04:04,100 'lower' operation. 74 00:04:05,800 --> 00:04:07,200 Here you have 'lower' operation. 75 00:04:07,600 --> 00:04:11,800 Now, you have something called 'swapcase', 'title', 'capitalize'. 76 00:04:12,300 --> 00:04:14,200 Let me go with the 'swapcase'. 77 00:04:15,300 --> 00:04:17,100 Right. This 'swapcase' is nothing 78 00:04:17,100 --> 00:04:20,399 but directly I'm going to print your result your string '.' 79 00:04:20,600 --> 00:04:21,899 simply 'swapcase'. 80 00:04:23,300 --> 00:04:26,800 See, observe the last output. What you are getting? lower 81 00:04:26,800 --> 00:04:29,800 case into 'upper', uppercase into 'lower'. That's it. 82 00:04:30,600 --> 00:04:33,100 But once again remember that whatever you are performing 83 00:04:33,100 --> 00:04:36,200 '.' operation that is not going to disturb your original 84 00:04:36,200 --> 00:04:39,200 string, only while printing it is modifying. 85 00:04:39,600 --> 00:04:43,200 So if you want to capture 'swapcase' result, you can 86 00:04:43,200 --> 00:04:46,700 store this result into some variable like your second line. 87 00:04:47,700 --> 00:04:49,900 Right. So this is 'swapcase'. 88 00:04:49,900 --> 00:04:52,500 [no audio] 89 00:04:52,500 --> 00:04:57,200 Now guys, I want to print my string in terms of 'title' 90 00:04:57,200 --> 00:05:02,400 format. So 'title' is nothing but printing each and every letter 91 00:05:02,400 --> 00:05:07,100 of a word, starting letter of each and every word in terms of capital. 92 00:05:08,100 --> 00:05:11,200 So already we have here 'capitalize'. 93 00:05:11,200 --> 00:05:15,600 Let me remove this small letters "python scripting tutorials". 94 00:05:17,300 --> 00:05:20,200 Now if I run the script and see the output for last 'print' 95 00:05:20,200 --> 00:05:23,300 statement, you are getting "P" capital, "S" capital, "T" capital 96 00:05:23,300 --> 00:05:26,200 because you are converting your given string into 'title' format. 97 00:05:26,200 --> 00:05:32,800 'title' format is nothing but each and every, in each and 98 00:05:32,800 --> 00:05:35,500 every word the starting letter should be capital. 99 00:05:35,500 --> 00:05:37,500 That's what we are doing with the help of 'title'. 100 00:05:39,200 --> 00:05:42,100 Right. Then 'capitalize'. 101 00:05:42,300 --> 00:05:44,900 Let me give, let me take one more string called 'my_new_str', 102 00:05:44,900 --> 00:05:45,800 you can take anything. 103 00:05:46,800 --> 00:05:49,500 I'm taking simply small letters "python scripting". 104 00:05:49,500 --> 00:05:51,400 [no audio] 105 00:05:51,400 --> 00:05:57,000 So guys I want to make my string in terms of capitalized 106 00:05:57,000 --> 00:06:04,200 format, right. See 'capitalize' format is nothing but observe 107 00:06:04,200 --> 00:06:06,800 the output, you can understand. Only the starting letter in 108 00:06:06,800 --> 00:06:10,600 a given string you are making it as a capital. That's it. 109 00:06:11,200 --> 00:06:13,900 That is the format of 'capitalize', right, capitalized. 110 00:06:16,700 --> 00:06:17,700 Fine. So guys, 111 00:06:17,700 --> 00:06:21,000 these are some of the operations on your given strings 112 00:06:21,300 --> 00:06:26,300 to convert one case to other case, or 'swapcase', or 'title', or 113 00:06:26,300 --> 00:06:28,700 'capitalize', right. 114 00:06:29,000 --> 00:06:32,600 So guys instead of your you know 'lower' you can also perform 115 00:06:32,600 --> 00:06:35,500 one more operation called, I will do one thing, 116 00:06:36,700 --> 00:06:38,500 only for 'lower' or 'upper', 117 00:06:38,900 --> 00:06:41,000 you don't know whether given string is there in lowercase 118 00:06:41,000 --> 00:06:42,000 or uppercase, 119 00:06:43,200 --> 00:06:48,000 but the thing is you want to convert your entire string, 120 00:06:48,000 --> 00:06:50,100 [no audio] 121 00:06:50,100 --> 00:06:51,400 like 'swapcase'. 122 00:06:51,600 --> 00:06:52,600 Let me do one thing, 123 00:06:53,600 --> 00:06:54,800 'casefold' 124 00:06:54,800 --> 00:06:57,800 [no audio] 125 00:06:57,800 --> 00:07:03,900 'print', your new string '.casefold' and observe 126 00:07:03,900 --> 00:07:04,900 the output what you are getting. 127 00:07:07,600 --> 00:07:09,200 'my_new_str', yeah, I commented that, right? 128 00:07:09,200 --> 00:07:12,500 Let me enable this. 'my_new_str', where it is? Yeah, 129 00:07:14,200 --> 00:07:15,400 instead of 'my_new_str' 130 00:07:15,400 --> 00:07:18,800 I will take 'my_str' variable. Anything. You can apply 131 00:07:18,800 --> 00:07:19,800 on any string, right? 132 00:07:19,800 --> 00:07:22,800 [no audio] 133 00:07:22,800 --> 00:07:23,800 Observe the output. 134 00:07:23,800 --> 00:07:27,800 [no audio] 135 00:07:27,900 --> 00:07:31,800 Right. So you are converting your entire string, even though, let me 136 00:07:31,800 --> 00:07:33,400 take here capital 'S'. 137 00:07:35,100 --> 00:07:36,300 something called 'G'. 138 00:07:37,800 --> 00:07:40,700 Any modification. See the output. What you are getting? 139 00:07:43,500 --> 00:07:46,900 Right. You are getting all in terms of lowercase. 140 00:07:46,900 --> 00:07:49,400 [no audio] 141 00:07:49,400 --> 00:07:51,200 Fine. So instead of 'lower' operation 142 00:07:51,200 --> 00:07:53,300 you can also perform 'casefold'. 143 00:07:55,100 --> 00:07:57,200 Right. Fine. So guys, 144 00:07:57,200 --> 00:08:01,000 these are some of the operations to convert your strings 145 00:08:01,400 --> 00:08:05,000 from one case to other case, right? 146 00:08:05,800 --> 00:08:08,500 Okay. Okay guys, thank you for watching this video. 147 00:08:08,500 --> 00:08:19,200 [no audio]