Friends, as of now we completed three types of operators,
right? They are arithmetic, assignment, and comparison operators.
Now, we are going to discuss two more operators.
They are identity and membership operators.
See why we are using, how we can use them in our
real-time, right. First
let me go with the identity operators. See identity operators
are used to find the type of your object.
[no audio]
It may be class.
What is the type of your object?
It may be class or type,
maybe object.
I mean for time being let me give you a very simple example.
[no audio]
I'm going to open my terminal.
[no audio]
Okay, fine. Just observe here.
We have some 'x' value, or let me define some new value for
'x', and 'y="hi"'. Then what is the type of your
'x'? Integer. Then what is the type of your 'y'?
[no audio]
So this is type. 'type()', your variable suppose 'x' and 'y'. Now,
let's say I am going to define one more variable called 'y',
'y=7', then what is the type of your 'y'?
Integer. Guys if I check 'x==y', no, 'False'. But 'x' and 'y' type is same.
What is the type? Integer type. Now,
I want to verify suppose for two variables whether the type
is similar or not.
I mean, let's say is 'type(x) is type(y)'. That means,
are they equal? Yes, 'True'.
But if I take 'type(x) is type()', let me define
[no audio]
'z=', some string. Now, you know 'type(z) is string. So 'x'
is integer and 'z' is string.
Now, what I am doing is I am going to compare 'type(x) is type(z)'.
No. 'type(x) is not 'type(z)'.
Yes, they are not equal.
We know that, because we know what the value we stored in
'x' and 'y', that's why 'type(x)' is integer and 'type(z)' is string,
but we are saying that yes, they are not, they are not equal
in type wise.
Yes. So in identity operators we have two types of operators, they are
'is' and 'is not'. So guys simply remember that identity operators
are used to find the type of your variable suppose or type
of your variable, right, or your object. Sometimes you know,
you are going to get your type maybe class or some object.
So for time being we know if you find the type of some variable
you're going to get either integer or float or complex or
string or byte, right?
Well, going forward we will see
whenever if we get some different types there
again we can use this identity operators.
Right. Fine. Then next one is membership operators.
See membership operators are used to validate the membership
of a value.
[no audio]
Anyway by seeing this you don't get much information, but
I want to give one thing. First thing, very simple information
guys. Observe this. I have a list of values called 4, 5, 6, 7
[no audio]
Right. '6 in x', Yes.
'90 in x', no, right.
Let us assume that in your real time you are doing some script.
The purpose of your script is, right,
first of all you have some valid,
let us assume valid Java versions.
Let's say 1.6 and 1.7,
or let me take 1.9 as well, 1.8,
[no audio]
and then 1.9. Just assume that these only your valid Java
versions. You should have only these Java
versions on your environment.
What happened? Something wrong.
[no audio]
1.6, yeah. I missed here quotation. Fine.
Okay, first before writing your Python Script, right,
first of all I am assuming that 1.6, 1.7, 1.8, and 1.9 are valid
Java versions.
Right. These are the valid versions but on my host what is
the Java version I have I don't know, but through Python Script
just assume that, because as of now you cannot write your
script to find Java version from your local host. Just assumption.
So, 'host_java',
[no audio]
I'm finding like this, something like that, but I'm not going
to write. I am writing some logic, through that I got version as 1.5.
Now what I have to do is, if your 'host_java',
[no audio]
if it is there in your valid then I can say, host consists of valid Java
version. So 'host_java in valid_java'?
No, 'False'.
Now, I can say that, now I can say that, right, your host does
not consist of a valid Java version.
Let me write simple script for this.
[no audio]
Nothing is the there, membership. Something is there in a given
group of values or not, that's it.
[no audio]
Very, very useful in your real time. Situation is same,
I mean scenario where you can use your membership operators
that scenario is same.
[no audio]
Let me copy. These are the 'valid_java' versions, and with some
logic. As of now directly
I am writing your 'host_java'.
But what I will do is in your real time I will add some
logic to get the 'host_java',
whatever the version is there.
Now, what I am doing is, 'if', as of now I don't know
about your 'if' statement, just observe that. 'if host_java
in valid_java', then I can say 'print("host consists of
[no audio]
valid Java version"), 'else:'
[no audio]
"host consists of", or "host deployed with",
instead of "consist", you can use "host deployed with invalid
Java version.
[no audio]
So assume that this is one script,
okay, and I am going to run this script. Just see the output
what you are getting. "Host deployed with invalid Java
version". Now, let us assume that you are going to run this
script on another server.
There you have 1.7. Now if you observe what is the code you're getting?
"host deployed with a valid Java version".
That means some particular value, whether it is there in a
given list of values or not,
right, for that you're going to use membership operator.
Not only that, just assumption, one more thing, because
these membership operators are very, very important
I am going to give one more example. That is, there are some
'db_groups', or there are some predefined 'db_users' or
'admin_user', something like that,
okay, just assumption
So some 'db_admin' user.
Then let us assume that
[no audio]
'db_conf' user,
[no audio]
'db_installation' user, something like that, okay.
Now I have some user, with that user
I need to start my application.
Just assume that. I mean I need to start my DB, just assume
that the users which are there in this,
let me take this as 'db_users', the users which are
there in this, they only can start your db application.
Just assume that.
Right. So in my hand, I have some user, random user.
I don't know whether that user is a valid DB user or not.
Just I got some random user.
Let's say 'db_admin'. See if this user is there in a given group 'db_users'
then I can allow to, I mean you can allow that user to start
your DB application.
That's why what I am doing is, right, 'if' your DB, or let's
say a 'random_user', right, 'if random_user in 'db_users', then
I can say 'print'.
"yes this user
[no audio]
is allowed to start db")'. That's it.
'else: print("
[no audio]
this is, this user
[no audio]
is not a valid user, or authorized, is not a valid user
to start db", right. First
let me run this code and observe the output. Before that
I am going to comment your previous code.
[no audio]
So guys, we will write a script to find out even this db_users,
valid db_users on your particular host. Right.
So everything we can write a script but initially, right,
I cannot go and write some complicated script, and I don't
want to confuse you that is why I am taking simply, directly the
output. Okay, observe the output. First,
if 'db_admin', yes, this user is allowed to start. Now,
let us assume that there is some user you don't know, some
'xyz' user, before going to start your DB by that 'xyz' user
what I will do is, if that 'random_user' in my 'valid_db' users
list then only I have to, otherwise I have to say, see the output,
"This user is not a valid user to start db".
So simply what you are doing, you are checking something is
there in a given list or not. To check that we are using membership operators.
[no audio]
Right. So whatever the thing you have, right, if that thing is
in the list of values, you will get output as 'True' whenever
if you are going to compare, and, sorry, whenever you are going
to use your membership operators, 'False'. And you have one more
thing, 'not in',
[no audio]
whether given value is not there in a list.
Yes, not in. 'True'.
Right. So you have two types of membership operators,
they are 'in' and 'not in'. Guys, maybe little bit confusion,
but while writing scripts with your 'if' condition while going
forward, you will get a clear clarity on these identity operators
and membership operators. For time being just assume that some
value you have to compare, you have to check whether it is
there in the given list of values or not. To check that we
are using membership operators. That's it. Okay.
[no audio]