Hello In this tutorial.
We are going to discuss about the bullying data type Python uses boolean variables in order to evaluate
conditions consider this statement.
7.
Greater than 3 because 7 is greater than 3.
Python would return true since 10 is less than or equal to 20.
In this case is when the Boolean value true is not done next.
This is the not equal to operator.
So by then checks.
If these string on the left is same as a string then the right.
Since this is not true the output would be once
next.
The double equal to operator.
We know that that the single equal to operator is used for variable assignment.
If we use a double equal to operate it means the number on the left is compared to the number on the
date.
It checks if both these numbers are the same or not since 5 is not equal to 6.
This would do it on flight in Python.
That at 6 comparison operators which all produce a boolean deserve the boolean values false and true
are the only boolean objects.
These objects behave like the values 0 and 1 respective mixed bool method.
The ball method converts a value to boolean using the standard road testing procedure.
And this is the syntax for the bool mentor.
So if we pass this statement 7 greater than 3 to the bool method Python should return the Boolean value
true similarly if we pass this statement to the ball method Python returned the Boolean value true.
So let's test this in our Jupiter notebook so here in this line in the cell I have two strings.
Cats and dogs and I want to compare both of the strings and then return Boolean value true or false.
So I have parse this expression to the ball method and then let execute.
This returns true because the expression on the left is not equal to the expression on the right.
Next let us say Let us compare the two numbers.
10 equal to equal to 20.
So as we have discussed before these single equal to operate word is used for assignment whereas the
double equal to operator is used to compare variables or expressions.
So let's execute this line of code.
So this returns false because 10 is not equal to 20.
It is not mandatory to pass a value to the bool metal if you do not pass a value.
The bool method returned false
in general use ball takes a single parameter value.
So let's test this in the Jupiter note book so let's not fives a new value to be bool mentor then execute
this line so it return defaults.
So if you do not pass any value to the bool method it returns the Boolean value false.
Similarly if you pass falls to the bool method it returns a false and also the Integer 0 or the floating
point number zero point zero the output would be acquired.
Similarly if you pass an empty string on an empty list or and or add an empty tuple the output would
be false.
Also if you pass an empty dictionary the output is quite so let pass the Boolean value falls to the
method bool so it is returning applies.
Let us pause.
0 0 in best motorboat the floating point numbered 0 0 0
let us change this.
Number two to two point or and then execute it or done to grow similarly if you pass an empty string
so I'm sure I'm not going to endure anything in between the deem limited single quote so it does you're
turning the quote Let us pass an empty list a list is denoted with the square brackets.
So it is returning a points so this is about the bold matured.
Consider this expression.
We know Python returned the Boolean value true when it evaluates the statement so I can also assign
this expression to a variable.
And now when I rent this variable X the result would be true.
We can assign a boolean expression to a variable.
Say for example X is equal to see a greater than nine.
So in this case the output of this boolean expression assigned to the variable x.
So let's go execute this line of code and then print the variable X in order to check the output and
then print x.
So it does returning a file so we can assign boolean expressions to a variable like this.
Also you can print the result of boolean expressions using the print function.
Say for example you want to test it for 30 is equal to hard to say for example you want to compare these
to the number thirty with the number 30 using the double equal to sign.
So after you execute this the print function returned the output of the boolean expression let us consider
this example.
We have 3 the worlds in which A is assigned to 10 B is assigned to 7 and c is assigned to 6 and we have
2 expressions used here we are using the comparison operators to compare the variables in B and the
greater than or equal to operator to compare the variables A and C since we have two conditions to evaluate.
We can use the the fight in logical operators and or and non to combine more than one condition C for
example I want to check if both of these expressions are TRUE OR NOT
I CAN USE THE and operating in this expression.
The first expression used is true because 10 is greater than or equal to 7.
The second expression is also true so finally Python would return the Boolean and do true so if the
board the conditions are true then the expression as a whole returned the Boolean value true.
The logical operators in Python combine two or more conditions and perform logical operations D and
operate.
Returns true if both the opposite ends at true coming to the odd operator the odd operator returns true
if e did of the opposite end.
Is true
the not operated
if a particular condition is true the not operated that don't fault means it complement the operation
in this cell.
We are comparing the the number 10 with the number 10 using the double equal to operator.
Then if we print this line of code it returns true if we use the not operator before this expression
and then execute it invert the doors.
Next is the membership by an operator.
These operators to test whether their value is a member of a sequence and this sequence could be a list
of a string tuple and we have two Python membership operators in and not in
so I want to check whether the character T is a substring or the string python and then evaluate this
too.
So this is true since this character T is present in Python and this chick and not the example.
Let us check if this particular substring is present in python in the string python and then execute.
So since Python could not find t or end in the string Python it has returned a false letter saying we
will now use the membership operator not in and then execute.
So in this case it would return true next is identity operators.
We have two identity operators is is nine is evaluates to true.
If the variable than either side of the operator point to the same object and false otherwise is not
evaluated two fold.
If the variables on either side of the operator bind to the same objects and true otherwise.
So let's understand the identity operators is and is not using an example.
Identity operators using a simple example here we have two variables A and B they are pointing to the
same memory location containing the value 10 and there is another variable C that is pointing to a memory
location containing the value 15 so a and b a it.
And when we use the identity operator A is B.
This should return true because are pointing to the same memory location same value and a C.
This should return false because they are pointing to different values.
So what would this expression red done.
B is not C and this is true let us check this in the Jupiter note book.
So I have defined the variables A B and C.
Now let us test the identity.
Operator e is B.
So this is true because a and b are binding to the same object.
Next e use C this is false because a and c not binding to different values 10 and 15 next B is not C
and this should return true.
And this is about the identity operators.