One more type of data type you should be aware of will be the boolean
operations or the boolean values. Typically, it's gonna be two of them.
You either have true or false
and it will depend largely on the outcome of certain kinds of operations.
Now, as an example
over here, I have the variable X equals five, the variable Y equals 10.
Now I have my very first print function in here that says X
is equal to Y.
The second is X is less than Y.
So
with booleans, you either have true or false.
Now, what do you think the answer for the very first print would be?
Well,
the answer obviously would be false because five is not equal to 10 while
the second should be true because X is in fact less than Y.
So now if I go ahead and run this program,
now you can see we have false and true.
These are what we refer to as the boolean values or the boolean
operators.
And we typically use them whenever we're
trying to create loops or conditional statements.
Don't worry
we're going to talk about those in the next section.
But typically, we may want to write a program that will check to see if something
has happened
and then if it has happened, meaning if it's true,
then do something. Or we can also say
if this thing hasn't happened.
Therefore, if it is false, then do something else.
So we're going to be making use of boolean
operators and values a bit later.
But
the thing about boolean
values and operations is that
they work with the comparison operators like your equals
to less than is equal to and so on.
But we also have what we call the logical operators,
logical operators will be things like and
or, or not.
So as an example, let me give you
another
program in here. Let me, first of all say A
uh equals true.
OK?
And then B equals false.
By the way, please note that
the true and false here are not strings
and in all strings because you can see that
it starts with a capital T
and with the false, it starts with a capital F.
So Python automatically knows that OK, you're dealing with booleans in here.
So
if I wanted to write a print function in here that says something like let's say
A
and
B,
let me write another one prints, let's say A or B
and then the last one prints
and I'm gonna say, let's say not a.
What do you think the answers will be for this three?
Typically whenever you're dealing with the logical operators
and you're comparing
two or more values,
all of them will need to be true whenever you're using the end statement.
If one of them is false, then the answer will be false. OK?
The opposite is with all.
So if you're saying true or false, it's going to be true.
If it's true and false, the answer will be false.
And then obviously, for the last one in here,
not a would be false because not a means the opposite of true,
opposite of true is false. So
if I run the program right now,
you will see once again that A and be true and false
will always be false while true or false will be true,
while not A
will be false.
So once again Bullen operators and values, they work with logical operators as well
such as your end or or not.
And of course,
your comparison operators such as your equals to
or is not equal to less than greater than
and so on.
So we're going to be working with boolean
operators as we progress in the course. Thank you for watching.
I will see you in the next class.