Welcome back.
In this video, I want to talk about the idea of toothy and falsely.
What do they mean?
And you'll hear this a lot in Python programming.
You see, up until now, you've used booleans here as values.
So it was really easy.
If true and true, then run this code.
But Python can do other things as well.
For example, if this was five and this was, let's say hello, what do you think will happen here in
our program?
Well, if I click Run.
You are old enough to drive and you have a license.
Is that what you expected?
And this is because what Python does underneath the hood is actually convert these to booleans for you.
So it's almost as if it is doing this remember type conversion where converting the type.
To bullion as soon as we get to this if statement because python is saying hey I want.
True or false I don't care what is old is I don't care what is licensed is just give me true or false
so I know whether to do this or to go to the else block.
Now, if I was to just print.
Let's do this here.
Let's do print bullion.
Hello?
And then finally, print bullion.
Five.
Let's see what we get.
We get true.
True.
And this is what we call a truth value in Python.
That is it's a truth we value because if we run the Boolean type conversion on it, it evaluates into
true what's a false value.
Well, if I do zero and if I do, let's say an empty string and I click run.
Those are falsely that is it's not actually false, but it is false because if we run Boolean on it
to Python, it's going to say, oh, this is false and zero, that's false.
And that kind of makes sense, right?
And if you actually go to StackOverflow, if you've never seen StackOverflow before, if you ever have
programming questions and you're Googling them, usually the top five answers will contain either one
or two StackOverflow answers.
And basically what happens is people ask questions like, what is truth and false in Python?
And you get answers.
So you can see over here that it has four answers and you usually look for the checkmark, which means
that this is a verified answer.
It means that, hey, this question owner has accepted it as the best answer.
So the person who asked this question just said, Yeah, this is the right answer, this is the best
one.
But you also have other people voting.
So you can see that this answer received 46 marks, and although it was marked as the correct answer
by the user, maybe somebody else came along later on and gave an even better answer.
So now we have 123 upvotes and you see that this answer is a lot better.
All values are considered truth except for the following.
So you can actually see here that in Python, these values are considered falsely.
You can see zero here.
You can see an empty string here.
And then there's a few other ones.
Empty set.
You have an empty dictionary, empty list, empty tuple.
You have decimals, you have things like fractions, you have 0.0 false is that and also none is falsely
so that if I type in none here.
That's false, too.
Now, you don't need to memorize this because most of the time it's it makes sense.
Right.
But it helps us do conditional logic very nicely.
For example, let's remove this and let's say that we have a user and this user has to have a password
and a username.
If, let's say the username is Johnny and the password is one, two, three.
Well, instead of me saying, hey, if this user has password and username and we're not checking if
the username exists or password exists, we just want to make sure, Hey, did this person fill out
the form and did they try to submit a username and password?
I can just simply say password and username.
And I don't have to worry about converting this to a bullion or anything like that, because if password
and username exist, then try to log them in and you see that it reads a lot nicer because each one
of these get evaluated into a truthful and false value.
It's a nice little feature to keep Python.
Well, nice and simple and reading like English.
I'll see you in the next video.
Bye bye.