1 00:00:00,000 --> 00:00:02,200 [no audio] 2 00:00:02,200 --> 00:00:03,500 Friends, here we are going to 3 00:00:03,500 --> 00:00:06,500 discuss some more operations on your strings, 4 00:00:06,900 --> 00:00:11,600 but the result of this operations is Boolean data. 5 00:00:11,600 --> 00:00:16,700 That means the result you will get like either true or false, 6 00:00:17,500 --> 00:00:21,800 right? Let me take the operations of your strings which 7 00:00:21,800 --> 00:00:23,900 will give the result as a Boolean data. 8 00:00:24,300 --> 00:00:27,500 So before that guys let me open my Python Shell. 9 00:00:28,000 --> 00:00:31,300 I mean first the command line, then type 'python', and you will 10 00:00:31,300 --> 00:00:35,400 enter into Python terminal, right. There define any string. 11 00:00:35,500 --> 00:00:37,500 Let's say, my_str= 12 00:00:37,500 --> 00:00:40,100 [no audio] 13 00:00:40,100 --> 00:00:41,300 "Hello", anything. 14 00:00:41,300 --> 00:00:44,000 [no audio] 15 00:00:44,000 --> 00:00:48,300 Then simply 'print(dir(my_str))'. 16 00:00:48,300 --> 00:00:51,300 [no audio] 17 00:00:51,300 --> 00:00:52,900 You have here different 18 00:00:52,900 --> 00:00:53,900 operations, right. Already 19 00:00:53,900 --> 00:00:56,200 we know how to get these operations, and already we have seen 20 00:00:56,200 --> 00:01:00,300 some of the operations like 'upper', 'title', 'swapcase', right, 21 00:01:00,300 --> 00:01:04,599 and then 'lower', 'capitalize', something 'casefold' we have seen. 22 00:01:06,000 --> 00:01:11,500 Now, I want to go with some other operations such that 23 00:01:12,700 --> 00:01:15,800 the result should be either true or false, or whatever the 24 00:01:15,800 --> 00:01:19,300 operations we are going to discuss now that operation's results 25 00:01:19,300 --> 00:01:21,800 is like true or false, or simply Boolean data. 26 00:01:22,800 --> 00:01:27,800 Let's take very simple operation first, 'endswith', right. Guys, 27 00:01:27,800 --> 00:01:30,200 let me open my editor. 28 00:01:31,400 --> 00:01:35,300 So I am going to write a Python script name for that, right. 29 00:01:35,700 --> 00:01:37,600 So let me take Python script name as 30 00:01:37,600 --> 00:01:39,600 [no audio] 31 00:01:39,600 --> 00:01:41,600 'boolean_result_ 32 00:01:41,600 --> 00:01:44,000 [no audio] 33 00:01:44,000 --> 00:01:48,400 string_operations'. So guys these operations are very, very helpful 34 00:01:48,400 --> 00:01:49,700 in your real time. 35 00:01:50,700 --> 00:01:55,600 Let's say I am taking 'my_str=', suppose simply "Python". 36 00:01:56,900 --> 00:02:00,000 Okay. Now what I am doing is I am checking, 37 00:02:00,000 --> 00:02:01,800 [no audio] 38 00:02:01,800 --> 00:02:02,800 'my_str' 39 00:02:04,100 --> 00:02:05,100 "." 40 00:02:05,100 --> 00:02:07,500 [no audio] 41 00:02:07,500 --> 00:02:13,400 'startswith("p")'. Is it starting with "p"? In that case you 42 00:02:13,400 --> 00:02:15,900 will use this operation. See the output. 'False'. 43 00:02:16,000 --> 00:02:18,300 The reason is you are starting with capital "P", 44 00:02:18,400 --> 00:02:19,800 but you're checking with small "p". 45 00:02:20,900 --> 00:02:24,000 Now, is it starting with small capital "P"? Yes, 'True'. 46 00:02:23,900 --> 00:02:25,900 [no audio] 47 00:02:25,900 --> 00:02:30,000 Right. So you will take this type of operations in your conditional 48 00:02:30,000 --> 00:02:33,700 statements. So you will come to know there how to use this. 49 00:02:33,800 --> 00:02:37,000 Before that you just try to observe the output. The same way 50 00:02:37,000 --> 00:02:40,200 I can check not only with single letter guys, 51 00:02:40,200 --> 00:02:42,600 I can also check with word also, no problem. 52 00:02:42,600 --> 00:02:47,900 'my_str.startswith', let's say "Python". No problem. 53 00:02:48,200 --> 00:02:49,800 Just check it. Yes, it's 'True'. 54 00:02:50,900 --> 00:02:52,700 Right. The same way 55 00:02:52,800 --> 00:03:00,900 you can also check like 'print(my_str.endswith)', 56 00:02:55,800 --> 00:03:02,700 [no audio] 57 00:03:02,700 --> 00:03:07,100 is it ending with "n"? You can take either single letter, or let's 58 00:03:07,100 --> 00:03:09,500 say I am taking "hon", no problem. 59 00:03:09,700 --> 00:03:12,000 I mean group of characters also you can check it. 60 00:03:12,200 --> 00:03:15,200 The only thing is if the given string is ending with "hon" then 61 00:03:15,200 --> 00:03:16,400 you will get output as 'True'. 62 00:03:17,200 --> 00:03:18,200 That's it. 63 00:03:18,200 --> 00:03:20,300 [no audio] 64 00:03:20,300 --> 00:03:23,000 So this is starting and ending, right. Then 65 00:03:23,000 --> 00:03:25,100 let me open your commands, 66 00:03:25,500 --> 00:03:29,400 I mean your terminal, and see that. Let me take something called 67 00:03:29,400 --> 00:03:33,600 [no audio] 68 00:03:33,600 --> 00:03:35,300 let's say 'islower'. 69 00:03:36,000 --> 00:03:37,700 You have likewise, you know so many operations. 70 00:03:37,700 --> 00:03:38,900 Let me take 'islower'. 71 00:03:40,000 --> 00:03:43,600 'print(my_str.islower)'. 72 00:03:44,600 --> 00:03:46,900 I mean is it in lower case letters? 73 00:03:46,900 --> 00:03:51,200 No, because first letter is capital, remaining all are small 74 00:03:51,200 --> 00:03:53,900 that's why you'll get output as 'False'. See the output. 75 00:03:53,900 --> 00:03:56,400 [no audio] 76 00:03:56,400 --> 00:03:58,200 Then, guys 'islower', 77 00:03:58,300 --> 00:04:01,100 'isupper', this type of operations are important in your 78 00:04:01,100 --> 00:04:02,400 real-time. 'isupper' 79 00:04:02,400 --> 00:04:04,400 [no audio] 80 00:04:04,400 --> 00:04:10,400 this is also 'False' because your letter, your string's, your string 81 00:04:10,400 --> 00:04:14,100 characters are not, all characters of your string are not in 82 00:04:14,100 --> 00:04:15,400 uppercase, only first letter, 83 00:04:15,400 --> 00:04:17,300 that's why you're getting 'isupper' as 'False'. 84 00:04:18,800 --> 00:04:22,500 Let me take 'my_str.istitle'. 85 00:04:24,200 --> 00:04:28,600 Yes, you will get 'True'. You know 'title' is nothing but if 86 00:04:28,600 --> 00:04:30,600 you have suppose some multiple words in a given string 87 00:04:31,900 --> 00:04:35,000 the first letter of your each and every word should be a 88 00:04:35,000 --> 00:04:38,500 capital. That format is there no, that's why you are getting 'True'. 89 00:04:38,900 --> 00:04:43,800 Suppose if I add something like "Python tutorials", now you'll 90 00:04:43,800 --> 00:04:47,300 get 'False' because in the second word "t" is small. 91 00:04:47,400 --> 00:04:50,000 Let me take it as a capital and check it now. 92 00:04:50,500 --> 00:04:51,500 Yes, now it's 'True'. 93 00:04:56,200 --> 00:04:59,000 Right. So 'title' is done. Likewise 94 00:04:59,700 --> 00:05:02,100 let me take some, 'isspace'. 95 00:05:03,000 --> 00:05:04,900 So is there any space in the given string? 96 00:05:05,500 --> 00:05:08,900 Is there any space in the given string? So for that you can 97 00:05:08,900 --> 00:05:10,600 use this operation, 98 00:05:11,800 --> 00:05:14,200 'isspace'. Yes, we have a space 99 00:05:14,200 --> 00:05:15,900 no, that's why you're going to get output as, 100 00:05:17,200 --> 00:05:19,500 sorry, 'isspace' 101 00:05:21,200 --> 00:05:24,500 You're having, along with your space you're having letters as well, right? 102 00:05:25,000 --> 00:05:30,200 Let me take one more example here, only space. The thing is 103 00:05:31,200 --> 00:05:38,900 'my_new_str' is only space, right. Now check on your new string 104 00:05:39,300 --> 00:05:41,000 'isspace'. Is it a space? 105 00:05:41,800 --> 00:05:42,800 Yes, 'True'. 106 00:05:43,600 --> 00:05:47,400 But if you observe on your given string, 'my_str' it is the 107 00:05:47,400 --> 00:05:51,500 combination of spaces and some alphabets. 108 00:05:51,600 --> 00:05:55,100 That's why it is giving result on this 'False', right? 109 00:05:56,300 --> 00:05:59,100 That's fine. Now, let me go with one more thing. 110 00:05:59,100 --> 00:06:01,200 [no audio] 111 00:06:01,200 --> 00:06:02,200 'isalpha'. 112 00:06:04,200 --> 00:06:05,300 Right. 'isalpha'. 113 00:06:06,900 --> 00:06:10,800 Nothing but, is your string consists of only alphabets? 114 00:06:12,100 --> 00:06:15,200 'my_new_str', let me take 'my_str' not 'my_new_str'. 115 00:06:15,200 --> 00:06:16,300 Let me take our string. 116 00:06:16,800 --> 00:06:18,100 So what is our string? First 117 00:06:18,100 --> 00:06:20,200 let me print it. This one, right? 118 00:06:21,800 --> 00:06:22,800 Is it alpha? 119 00:06:23,600 --> 00:06:24,600 Yes, 'True' no? 120 00:06:24,500 --> 00:06:27,900 [no audio] 121 00:06:27,900 --> 00:06:32,600 Why are we getting 'False'? You have space. Space is not the 122 00:06:32,600 --> 00:06:34,200 alphabet, right? 123 00:06:34,200 --> 00:06:35,600 Let me remove that space. 124 00:06:36,600 --> 00:06:38,800 Now, see the output. You're getting 'True'. 125 00:06:38,800 --> 00:06:41,500 [no audio] 126 00:06:41,500 --> 00:06:43,900 Right. So space is not alphabet, 127 00:06:43,900 --> 00:06:46,000 that's why 'isalpha' giving 'False'. 128 00:06:46,000 --> 00:06:47,600 If you remove that space it will give a 'True'. 129 00:06:49,800 --> 00:06:50,800 That's fine. 130 00:06:51,300 --> 00:06:55,300 Now, let me go with the one more thing called 'isnumeric' for 131 00:06:55,300 --> 00:06:56,600 your numbers, right? 132 00:06:56,600 --> 00:07:00,100 'isprintable', right, you can print. 'istitle', isupper'. 133 00:07:00,100 --> 00:07:05,100 Let me take one more thing called 'is', yeah, I will take this 134 00:07:05,100 --> 00:07:06,200 one, 'isnumeric'. 135 00:07:06,200 --> 00:07:10,000 [no audio] 136 00:07:10,000 --> 00:07:11,600 See that I am checking, 137 00:07:11,600 --> 00:07:15,800 'print(my_str.isnumeric)'. 138 00:07:17,300 --> 00:07:19,300 What is the output? You are getting output as 139 00:07:22,800 --> 00:07:25,300 'my_new_str', sorry. That is commented 140 00:07:25,300 --> 00:07:26,700 no. Let me take 'my_str'. 141 00:07:27,800 --> 00:07:30,700 See the error is, "my_new_str" is not defined, because we 142 00:07:30,700 --> 00:07:33,800 commented that. That's why Python is unable to identify that 143 00:07:33,800 --> 00:07:36,900 variable. Anyway, it's fine. Now see the output. What you 144 00:07:36,900 --> 00:07:38,700 are getting? 'False'. 'isnumeric', 145 00:07:39,900 --> 00:07:41,400 see our string is not numeric 146 00:07:41,400 --> 00:07:43,400 no, our string consists of alphabets. 147 00:07:43,700 --> 00:07:45,700 Let's redefine your string. 148 00:07:47,300 --> 00:07:54,100 equals to something which consists of only numbers, a string 149 00:07:54,300 --> 00:07:56,800 which consists of numbers. Now see the output. You are getting 150 00:07:56,800 --> 00:08:00,900 'True' because your string consists of only numbers. 'isnumeric'. 151 00:08:02,100 --> 00:08:06,000 Right. So guys this type of operations are very, very important. 152 00:08:07,400 --> 00:08:08,400 Right. 153 00:08:09,800 --> 00:08:13,000 So you have some operations, like you can check by going through 154 00:08:13,000 --> 00:08:16,200 document. This 'isalnum', 'isalpha', 155 00:08:16,200 --> 00:08:18,200 'isascii', 'isdecimal', right, 156 00:08:18,200 --> 00:08:21,400 'isdigit', 'isidentifier', 'islower', 'isnumeric', 157 00:08:21,400 --> 00:08:22,600 'isprintable', 'isspace'. 158 00:08:22,900 --> 00:08:29,300 Nothing is there. Simply 'help(str)' you will get all the operations, 159 00:08:29,300 --> 00:08:31,000 its meaning, right? 160 00:08:31,000 --> 00:08:33,700 You just go down, by entering 'capitalize' 161 00:08:33,700 --> 00:08:37,000 there is a meaning, right. 'casefold', right. 162 00:08:39,700 --> 00:08:43,000 So likewise you have all operations here. Just go with only 163 00:08:43,400 --> 00:08:46,600 'is' something, like that, which gives the result as Boolean 164 00:08:46,600 --> 00:08:47,900 data, 'True' or 'False'. 165 00:08:47,900 --> 00:08:50,900 So this guys, this type of operations are very, very important 166 00:08:50,900 --> 00:08:51,700 in your real-time. 167 00:08:52,100 --> 00:08:55,299 You just try to practice with your remaining operations 168 00:08:55,900 --> 00:08:59,000 which are there like this, right, 'isalpha', 'is' you know, 169 00:08:59,000 --> 00:09:02,900 'isascii', 'isdecimal', something like that, right. In next video 170 00:09:02,900 --> 00:09:05,900 we'll see some more operations on your strings, okay? 171 00:09:07,000 --> 00:09:09,100 Okay guys, thank you for watching this video. 172 00:09:09,100 --> 00:09:16,600 [no audio]