1 00:00:00,000 --> 00:00:04,099 Friends, as of now we completed three types of operators, 2 00:00:04,200 --> 00:00:08,900 right? They are arithmetic, assignment, and comparison operators. 3 00:00:09,000 --> 00:00:12,000 Now, we are going to discuss two more operators. 4 00:00:12,000 --> 00:00:15,000 They are identity and membership operators. 5 00:00:16,000 --> 00:00:18,800 See why we are using, how we can use them in our 6 00:00:18,800 --> 00:00:20,700 real-time, right. First 7 00:00:20,700 --> 00:00:26,100 let me go with the identity operators. See identity operators 8 00:00:26,100 --> 00:00:29,600 are used to find the type of your object. 9 00:00:29,600 --> 00:00:31,500 [no audio] 10 00:00:31,500 --> 00:00:32,799 It may be class. 11 00:00:33,500 --> 00:00:35,300 What is the type of your object? 12 00:00:35,700 --> 00:00:38,400 It may be class or type, 13 00:00:38,400 --> 00:00:39,400 maybe object. 14 00:00:39,500 --> 00:00:43,600 I mean for time being let me give you a very simple example. 15 00:00:43,600 --> 00:00:45,600 [no audio] 16 00:00:45,600 --> 00:00:47,200 I'm going to open my terminal. 17 00:00:47,200 --> 00:00:54,700 [no audio] 18 00:00:54,700 --> 00:00:56,300 Okay, fine. Just observe here. 19 00:00:56,400 --> 00:01:00,000 We have some 'x' value, or let me define some new value for 20 00:01:00,000 --> 00:01:05,200 'x', and 'y="hi"'. Then what is the type of your 21 00:01:05,200 --> 00:01:09,900 'x'? Integer. Then what is the type of your 'y'? 22 00:01:09,900 --> 00:01:12,000 [no audio] 23 00:01:12,000 --> 00:01:17,200 So this is type. 'type()', your variable suppose 'x' and 'y'. Now, 24 00:01:17,200 --> 00:01:20,500 let's say I am going to define one more variable called 'y', 25 00:01:20,500 --> 00:01:23,900 'y=7', then what is the type of your 'y'? 26 00:01:25,200 --> 00:01:35,100 Integer. Guys if I check 'x==y', no, 'False'. But 'x' and 'y' type is same. 27 00:01:35,400 --> 00:01:38,300 What is the type? Integer type. Now, 28 00:01:38,300 --> 00:01:44,200 I want to verify suppose for two variables whether the type 29 00:01:44,200 --> 00:01:45,600 is similar or not. 30 00:01:46,200 --> 00:01:55,700 I mean, let's say is 'type(x) is type(y)'. That means, 31 00:01:55,700 --> 00:01:57,500 are they equal? Yes, 'True'. 32 00:01:58,700 --> 00:02:05,800 But if I take 'type(x) is type()', let me define 33 00:02:05,800 --> 00:02:08,100 [no audio] 34 00:02:08,199 --> 00:02:13,100 'z=', some string. Now, you know 'type(z) is string. So 'x' 35 00:02:13,100 --> 00:02:15,200 is integer and 'z' is string. 36 00:02:15,500 --> 00:02:20,400 Now, what I am doing is I am going to compare 'type(x) is type(z)'. 37 00:02:20,700 --> 00:02:24,200 No. 'type(x) is not 'type(z)'. 38 00:02:24,200 --> 00:02:25,400 Yes, they are not equal. 39 00:02:25,400 --> 00:02:28,100 We know that, because we know what the value we stored in 40 00:02:28,100 --> 00:02:32,000 'x' and 'y', that's why 'type(x)' is integer and 'type(z)' is string, 41 00:02:32,000 --> 00:02:35,400 but we are saying that yes, they are not, they are not equal 42 00:02:35,400 --> 00:02:36,400 in type wise. 43 00:02:37,000 --> 00:02:42,700 Yes. So in identity operators we have two types of operators, they are 44 00:02:42,700 --> 00:02:48,100 'is' and 'is not'. So guys simply remember that identity operators 45 00:02:48,100 --> 00:02:53,300 are used to find the type of your variable suppose or type 46 00:02:53,300 --> 00:02:59,200 of your variable, right, or your object. Sometimes you know, 47 00:02:59,200 --> 00:03:02,900 you are going to get your type maybe class or some object. 48 00:03:04,400 --> 00:03:08,800 So for time being we know if you find the type of some variable 49 00:03:08,800 --> 00:03:12,300 you're going to get either integer or float or complex or 50 00:03:12,300 --> 00:03:15,100 string or byte, right? 51 00:03:15,100 --> 00:03:16,700 Well, going forward we will see 52 00:03:16,700 --> 00:03:20,100 whenever if we get some different types there 53 00:03:20,100 --> 00:03:23,000 again we can use this identity operators. 54 00:03:24,400 --> 00:03:28,700 Right. Fine. Then next one is membership operators. 55 00:03:29,700 --> 00:03:34,100 See membership operators are used to validate the membership 56 00:03:34,100 --> 00:03:35,100 of a value. 57 00:03:35,100 --> 00:03:37,300 [no audio] 58 00:03:37,300 --> 00:03:40,400 Anyway by seeing this you don't get much information, but 59 00:03:40,400 --> 00:03:43,800 I want to give one thing. First thing, very simple information 60 00:03:43,800 --> 00:03:49,800 guys. Observe this. I have a list of values called 4, 5, 6, 7 61 00:03:49,800 --> 00:03:53,000 [no audio] 62 00:03:53,000 --> 00:03:55,900 Right. '6 in x', Yes. 63 00:03:57,200 --> 00:04:01,100 '90 in x', no, right. 64 00:04:01,400 --> 00:04:04,300 Let us assume that in your real time you are doing some script. 65 00:04:04,800 --> 00:04:07,500 The purpose of your script is, right, 66 00:04:07,900 --> 00:04:09,900 first of all you have some valid, 67 00:04:10,100 --> 00:04:13,300 let us assume valid Java versions. 68 00:04:13,400 --> 00:04:16,600 Let's say 1.6 and 1.7, 69 00:04:17,800 --> 00:04:21,300 or let me take 1.9 as well, 1.8, 70 00:04:21,300 --> 00:04:23,700 [no audio] 71 00:04:23,700 --> 00:04:28,600 and then 1.9. Just assume that these only your valid Java 72 00:04:28,600 --> 00:04:30,700 versions. You should have only these Java 73 00:04:30,700 --> 00:04:32,500 versions on your environment. 74 00:04:34,800 --> 00:04:37,500 What happened? Something wrong. 75 00:04:37,500 --> 00:04:40,900 [no audio] 76 00:04:40,900 --> 00:04:44,700 1.6, yeah. I missed here quotation. Fine. 77 00:04:46,100 --> 00:04:49,600 Okay, first before writing your Python Script, right, 78 00:04:50,700 --> 00:04:55,600 first of all I am assuming that 1.6, 1.7, 1.8, and 1.9 are valid 79 00:04:55,600 --> 00:04:56,600 Java versions. 80 00:04:57,700 --> 00:05:01,600 Right. These are the valid versions but on my host what is 81 00:05:01,600 --> 00:05:04,300 the Java version I have I don't know, but through Python Script 82 00:05:04,300 --> 00:05:07,000 just assume that, because as of now you cannot write your 83 00:05:07,000 --> 00:05:10,800 script to find Java version from your local host. Just assumption. 84 00:05:11,500 --> 00:05:12,800 So, 'host_java', 85 00:05:12,800 --> 00:05:14,600 [no audio] 86 00:05:14,600 --> 00:05:18,000 I'm finding like this, something like that, but I'm not going 87 00:05:18,000 --> 00:05:21,800 to write. I am writing some logic, through that I got version as 1.5. 88 00:05:23,000 --> 00:05:25,800 Now what I have to do is, if your 'host_java', 89 00:05:25,800 --> 00:05:27,800 [no audio] 90 00:05:27,800 --> 00:05:32,700 if it is there in your valid then I can say, host consists of valid Java 91 00:05:32,700 --> 00:05:35,300 version. So 'host_java in valid_java'? 92 00:05:35,400 --> 00:05:36,500 No, 'False'. 93 00:05:36,500 --> 00:05:42,300 Now, I can say that, now I can say that, right, your host does 94 00:05:42,300 --> 00:05:45,000 not consist of a valid Java version. 95 00:05:45,500 --> 00:05:47,200 Let me write simple script for this. 96 00:05:47,200 --> 00:05:50,600 [no audio] 97 00:05:50,600 --> 00:05:53,100 Nothing is the there, membership. Something is there in a given 98 00:05:53,100 --> 00:05:55,700 group of values or not, that's it. 99 00:05:55,700 --> 00:05:59,800 [no audio] 100 00:05:59,800 --> 00:06:04,000 Very, very useful in your real time. Situation is same, 101 00:06:04,000 --> 00:06:07,600 I mean scenario where you can use your membership operators 102 00:06:08,300 --> 00:06:09,500 that scenario is same. 103 00:06:09,500 --> 00:06:11,400 [no audio] 104 00:06:11,400 --> 00:06:15,600 Let me copy. These are the 'valid_java' versions, and with some 105 00:06:15,600 --> 00:06:17,000 logic. As of now directly 106 00:06:17,000 --> 00:06:19,700 I am writing your 'host_java'. 107 00:06:19,700 --> 00:06:22,300 But what I will do is in your real time I will add some 108 00:06:22,300 --> 00:06:24,400 logic to get the 'host_java', 109 00:06:24,400 --> 00:06:25,600 whatever the version is there. 110 00:06:26,000 --> 00:06:29,700 Now, what I am doing is, 'if', as of now I don't know 111 00:06:30,000 --> 00:06:36,700 about your 'if' statement, just observe that. 'if host_java 112 00:06:36,700 --> 00:06:40,900 in valid_java', then I can say 'print("host consists of 113 00:06:40,900 --> 00:06:42,900 [no audio] 114 00:06:42,900 --> 00:06:46,500 valid Java version"), 'else:' 115 00:06:46,500 --> 00:06:51,200 [no audio] 116 00:06:51,200 --> 00:06:53,400 "host consists of", or "host deployed with", 117 00:06:53,400 --> 00:06:58,700 instead of "consist", you can use "host deployed with invalid 118 00:06:59,600 --> 00:07:00,800 Java version. 119 00:07:00,800 --> 00:07:06,300 [no audio] 120 00:07:06,300 --> 00:07:08,900 So assume that this is one script, 121 00:07:09,500 --> 00:07:13,900 okay, and I am going to run this script. Just see the output 122 00:07:13,900 --> 00:07:16,300 what you are getting. "Host deployed with invalid Java 123 00:07:16,300 --> 00:07:19,800 version". Now, let us assume that you are going to run this 124 00:07:19,800 --> 00:07:21,100 script on another server. 125 00:07:21,200 --> 00:07:25,300 There you have 1.7. Now if you observe what is the code you're getting? 126 00:07:25,400 --> 00:07:27,300 "host deployed with a valid Java version". 127 00:07:27,300 --> 00:07:30,600 That means some particular value, whether it is there in a 128 00:07:30,600 --> 00:07:32,400 given list of values or not, 129 00:07:33,500 --> 00:07:35,900 right, for that you're going to use membership operator. 130 00:07:36,800 --> 00:07:39,000 Not only that, just assumption, one more thing, because 131 00:07:39,100 --> 00:07:41,000 these membership operators are very, very important 132 00:07:41,000 --> 00:07:45,800 I am going to give one more example. That is, there are some 133 00:07:45,800 --> 00:07:51,200 'db_groups', or there are some predefined 'db_users' or 134 00:07:51,200 --> 00:07:52,900 'admin_user', something like that, 135 00:07:53,100 --> 00:07:54,400 okay, just assumption 136 00:07:54,900 --> 00:07:59,500 So some 'db_admin' user. 137 00:08:01,200 --> 00:08:02,700 Then let us assume that 138 00:08:02,700 --> 00:08:04,900 [no audio] 139 00:08:04,900 --> 00:08:06,600 'db_conf' user, 140 00:08:06,600 --> 00:08:15,000 [no audio] 141 00:08:15,000 --> 00:08:19,200 'db_installation' user, something like that, okay. 142 00:08:19,700 --> 00:08:23,600 Now I have some user, with that user 143 00:08:24,200 --> 00:08:25,900 I need to start my application. 144 00:08:26,200 --> 00:08:28,600 Just assume that. I mean I need to start my DB, just assume 145 00:08:28,600 --> 00:08:31,600 that the users which are there in this, 146 00:08:31,700 --> 00:08:34,900 let me take this as 'db_users', the users which are 147 00:08:34,900 --> 00:08:38,299 there in this, they only can start your db application. 148 00:08:38,200 --> 00:08:39,299 Just assume that. 149 00:08:40,000 --> 00:08:44,200 Right. So in my hand, I have some user, random user. 150 00:08:44,200 --> 00:08:47,100 I don't know whether that user is a valid DB user or not. 151 00:08:47,400 --> 00:08:49,200 Just I got some random user. 152 00:08:49,600 --> 00:08:56,000 Let's say 'db_admin'. See if this user is there in a given group 'db_users' 153 00:08:56,000 --> 00:09:01,200 then I can allow to, I mean you can allow that user to start 154 00:09:01,200 --> 00:09:02,300 your DB application. 155 00:09:02,400 --> 00:09:09,400 That's why what I am doing is, right, 'if' your DB, or let's 156 00:09:09,400 --> 00:09:17,200 say a 'random_user', right, 'if random_user in 'db_users', then 157 00:09:17,200 --> 00:09:18,800 I can say 'print'. 158 00:09:19,300 --> 00:09:21,000 "yes this user 159 00:09:21,000 --> 00:09:23,000 [no audio] 160 00:09:23,000 --> 00:09:27,700 is allowed to start db")'. That's it. 161 00:09:29,100 --> 00:09:32,000 'else: print(" 162 00:09:32,000 --> 00:09:34,500 [no audio] 163 00:09:34,500 --> 00:09:36,900 this is, this user 164 00:09:36,900 --> 00:09:40,500 [no audio] 165 00:09:40,500 --> 00:09:45,800 is not a valid user, or authorized, is not a valid user 166 00:09:46,600 --> 00:09:50,300 to start db", right. First 167 00:09:50,400 --> 00:09:53,400 let me run this code and observe the output. Before that 168 00:09:53,400 --> 00:09:55,300 I am going to comment your previous code. 169 00:09:55,300 --> 00:09:58,600 [no audio] 170 00:09:58,600 --> 00:10:01,800 So guys, we will write a script to find out even this db_users, 171 00:10:01,800 --> 00:10:04,800 valid db_users on your particular host. Right. 172 00:10:05,700 --> 00:10:08,500 So everything we can write a script but initially, right, 173 00:10:08,900 --> 00:10:11,800 I cannot go and write some complicated script, and I don't 174 00:10:11,800 --> 00:10:14,000 want to confuse you that is why I am taking simply, directly the 175 00:10:14,000 --> 00:10:17,500 output. Okay, observe the output. First, 176 00:10:18,800 --> 00:10:22,100 if 'db_admin', yes, this user is allowed to start. Now, 177 00:10:22,100 --> 00:10:24,400 let us assume that there is some user you don't know, some 178 00:10:24,400 --> 00:10:30,200 'xyz' user, before going to start your DB by that 'xyz' user 179 00:10:30,200 --> 00:10:34,400 what I will do is, if that 'random_user' in my 'valid_db' users 180 00:10:34,400 --> 00:10:38,200 list then only I have to, otherwise I have to say, see the output, 181 00:10:38,200 --> 00:10:40,800 "This user is not a valid user to start db". 182 00:10:41,400 --> 00:10:45,600 So simply what you are doing, you are checking something is 183 00:10:45,600 --> 00:10:51,100 there in a given list or not. To check that we are using membership operators. 184 00:10:51,100 --> 00:10:53,800 [no audio] 185 00:10:53,800 --> 00:10:59,100 Right. So whatever the thing you have, right, if that thing is 186 00:10:59,100 --> 00:11:02,000 in the list of values, you will get output as 'True' whenever 187 00:11:02,000 --> 00:11:05,200 if you are going to compare, and, sorry, whenever you are going 188 00:11:05,200 --> 00:11:09,200 to use your membership operators, 'False'. And you have one more 189 00:11:09,200 --> 00:11:11,700 thing, 'not in', 190 00:11:11,700 --> 00:11:14,000 [no audio] 191 00:11:14,000 --> 00:11:16,800 whether given value is not there in a list. 192 00:11:16,800 --> 00:11:18,300 Yes, not in. 'True'. 193 00:11:18,800 --> 00:11:23,000 Right. So you have two types of membership operators, 194 00:11:23,000 --> 00:11:27,500 they are 'in' and 'not in'. Guys, maybe little bit confusion, 195 00:11:27,600 --> 00:11:30,900 but while writing scripts with your 'if' condition while going 196 00:11:30,900 --> 00:11:34,900 forward, you will get a clear clarity on these identity operators 197 00:11:34,900 --> 00:11:38,900 and membership operators. For time being just assume that some 198 00:11:38,900 --> 00:11:42,500 value you have to compare, you have to check whether it is 199 00:11:42,500 --> 00:11:45,600 there in the given list of values or not. To check that we 200 00:11:45,600 --> 00:11:49,200 are using membership operators. That's it. Okay. 201 00:11:49,200 --> 00:11:51,306 [no audio]