-: Hi guys and welcome back.
Just a quick video to tell you about Booleans.
A Boolean is a value that can be either true or false.
And we can use that to make decisions,
for example, using Boolean logic,
we can tell whether a user's age is over 18.
Or whether the user's character in a game
has pressed the up arrow.
Things like that are what we need Booleans for
and they are everywhere in Python
and in Programming.
Let's learn more about them.
Booleans are created by using comparisons.
So, you can compare two things together
to calculate whether two things
are the same or different,
for example, if you print five equal equal five,
this is a Boolean comparison,
five equal equal five.
Notice that a single equal sign
is used to assign a value to a variable.
But two equal signs, one after another
are used to compare two things.
And what we're comparing here is,
five and we're gonna check whether it is
exactly equal to five.
So, these two numbers here are being compared
and we're going to get true,
if they are exactly equal
and we're going to get false if they are
in any way different.
So, if I run this here, you'll see
that we get true out.
As well as equal equal,
you can use the typical maths operators
such as greater than,
to calculate whether a number is greater than
another number.
And there you get false.
As a special case, you've also got,
exclamation mark equal, which is used
to tell whether two things are different.
So, what this reads as is,
is 10 different from 10?
So, again, you'll get true if they are different
and you'll get false if the are not different.
So, here we should get false,
because they are not different.
Other comparisons that are available
as well as equal equal, not equal
and greater than are less than
and greater than are equal to,
or less than are equal to.
And this is how you write them in Python.
So, you can check whether something is
less than one thing, whether it's greater than
or equal to something else
or whether it's less than
or equal to something else.
I'll say at this point,
that you can use these operations,
not only on numbers,
but on any other value including lists,
and tuples and strings and what not,
but they can behave differently depending
on what type of data you use them on.
We're going to learn more
and get more acquainted with how they behave
in different scenarios, as we go along
with better examples, of course.
So, these are the comparisons
and as well as comparisons, you've also got
a few Python key words
that you can use to calculate Booleans.
One of the more confusing key words in Python,
when you're talking about Booleans
is the ease key word.
So, here we've got two list,
friends and abroad and they have
the exact same elements inside them.
You can print whether friends equal equal abroad
and when you run this code,
you get back true,
because the equal equal sign,
when you're talking about two different lists,
compares whether the elements inside them
are the same.
And here, because you're comparing two strings,
then Python can detect
that these two lists are actually the same.
However, a lot of new Python developers
will try to do friends is abroad,
which is something you can do in Python.
But you won't get what you expect
because you get false.
That is because when you create a new list,
Python goes and creates some space
in its memory for this new list.
The elements can be stored somewhere else,
but the list itself has its own area in memory.
Then when you create another list,
it goes and creates another area in memory
for this other list.
The elements inside the list were created separately
and they could be the same between both lists,
but the lists themselves are different.
And that is what the is keyword checks in Python.
It checks whether two elements are exactly the same thing,
not whether they have the same elements inside them
or whether they are similar.
So, again the is keyword is to compare
whether two elements are the same thing.
So, if you do friends is friends, for example,
you're going to get true.
If say abroad equal friends up here
and then you check whether friends is abroad,
you're also going to get true
because you haven't created two lists.
You've just pointed the two variables
to the same list.
And that again is what the is keyword is for,
I recommend you almost never use it.
You're almost always gonna want to use
the double equal sign.
All right, that's it for comparisons
and this brief introduction to Booleans.
Let's learn more in the next video.
I'll see you there.