Oh yes and welcome back to another class of our course about Python.
The complete introduction I'm done now with some many things that can be used for you guys to create
your own programs and they are going to talk about another very important thing about Python.
So we are gonna talk about the if statement which is something that is very important for you guys to
understand.
If you want to create your own application.
So what exactly we are going to talk about in this course in the next class.
Well it's very simple.
We in this class we are going to talk principally about what is the if statement how it works.
We are going to talk about boolean variables since those are very important for you guys to be able
to use the if statement because without boolean you are not able to work with if statement and we are
going to talk about everything that is around if statements so we are going to talk about the OR and
Elif and not so we are going to create some small apps around all this.
So you guys will be able to understand what is it exactly and how it works.
All right.
So before we start in this subject we have to understand what is a boolean variable in this case it
boolean variable is simply a variable.
Well a boolean that a type start boolean that that is simply a data type that will have true or false
in it.
So basically we have strings that are text we have numbers that are well numbers and finally boolean
which are true or false.
So for the guys to understand let me write down something.
Let me write down a variable and store a boolean that type.
So in this case let's say I'll write down I want to keep and I store the value true.
So in this case what Python understands Python understands that this that type which is I want to eat
is equal to true.
So I want to eat.
Technically yes I want to eat.
So this is true in the other case that say for example I want to drink I want to drink.
This is another variable that we created in this case.
Let's say it's false.
So what Python understands but understands that this variable is true.
So he will return a value in consequence of this and that is false so he will return something based
on this answer.
So how words that if statement.
So how does a word that is very simple let's say something happens to you.
So let's say a situation happens to you and or you are creating something and you expect a certain outcome.
So you will ask yourself this question if this outcome appears I want this to happen.
If it doesn't appear I want something else to happen to this.
Exactly what Python will do.
And this is exactly what we'll do with our if statement we can for example add some other things if
this happens or this happens I want this outcome or if this happen and this happened I want this type
of outcome.
So that's exactly what we are going to do in this class.
All right.
So let's start this right now.
So the first thing I'll ask you guys to do is simply write down if so when you wrote down if what we
will want to do is write down are a variable in this case is going gonna be I want to eat.
So if I want to eat is true.
So in this case python on verifies automatically.
So that's the way that we will ask ourselves if it's true.
I want to print.
Let's have a pizza.
So in this case let's
let's have a pizza and if we run the app Well as you can see based on the returns let's have a pizza
so this is the condition the condition is.
If I want to eat well bite on return let's have a pizza.
So if for example here.
Right.
Don't.
False instead of true right down false and we run our app as you can see nothing will appear because
something will appear.
Only if we have a true value here.
All right let's say you want to say we want something to happen in the case that this is not true.
So in the case that this is true I will return let's have a pizza.
But in the case that this is not true I want something to happen.
So what exactly you do is very simple.
All right.
Don't else and I will write down what I want to print so.
Otherwise I want to return.
I'm good.
So in this case.
Write down a good
end if I want my app.
Well it's gonna it's gonna print I'm good.
So let's say I want to eat let's have some pizza and if I don't want to eat I will return.
I'm good.
So once again as you can see this is a way that we can use our well our if statement.
All right.
So another way that you guys can use it will be for example with if and so in this case we by on will
verify 2 or three two or three or an infinity of variables before giving.
Well the answer to in this case let's say for example if I want to eat and I want to drink or choose
in this case I want to drink or two.
So both of those variables are true this means that I want to return.
Let's have a pizza and let's say a drink.
So what Python will do Python will verify.
First of all is it true.
If yes he will verify is it is this variable true.
If it's both of them are true.
Python will print this.
If not python will print I'm good.
So let's verify it.
That's right down true here.
Just for you guys to understand and we run are up to in this case Python returns.
I'm good because this is true but this is false.
But if both of those variables are true.
So in this case where on True and true as you can see python will return let's have a pizza a drink
or and a drink.
So we run the app as you can see Python already done here.
Let's have a pizza and drink all right.
So right now that you guys understand this next thing that we want to do is work with the if and the.
Or so in this case python will verify if one of those variables is true.
So what we want to do is we'll write down right here instead of writing down and we'll write down more.
So if I want to eat or I want to drink I want Python to return let's go to the restaurant.
And we run the up so in this case as you can see both are true.
So python will return.
Let's go to the restaurant.
If only one of those is true
so as you can see if one of those is true and we run our up Python we'll still return.
Let's go to the restaurant.
Since we have used the OR right here were a statement.
If we change it by end it's not gonna work.
Because we don't have both of them that are respected.
But if we only write don't work it's gonna work because one of those one of those variables is equal
to true.
And this is what we ask Python to verify.
All right.
Right now that we understand all those things.
The next thing that we are gonna ask ourselves is if for example one to verify another statement or
in this case let's say for example we have I want to drink and let's say it's false if it's false.
Let's say I want Python to verify something else.
So in this case I want Python to verify if I want if I want to drink.
So in this case Python verified if I want to eat and it's false.
So let's say right now I want Python to verify if I want a drink.
So how exactly I will add the if statement in and Naif statement that already exists.
So it's very simple.
I will use the L if so in this case.
Elif when I use the Elif in an if statement it's simply I add a if statement statement inside of another
if statement.
So let's say this value is false.
So I will use the Elif and in this case I will write down my function.
So I want to drink and I will verify if I want to drink.
So if yes I want to drink what I will do.
It will simply print
let's have a drink.
Let's have a drink.
All right and otherwise
in this case I'll write down my else on the print I'm good.
Good.
Great.
So what you guys under.
So yes.
You see here.
So first of all I will ask Python to verify if I want to eat.
If yes I want to eat I want Python to print.
Let's go to the restaurant if I don't want to eat.
I won't bite on to verify if I want a drink if I want to drink.
I want Python to print.
Let's have a drink.
Otherwise I won't bite into print.
I'm good.
So if I run this up the first thing I'm gonna see is I'm good because both of those values are false.
If let's say the value I want to eat is true
right there so Python verifies I want to eat.
It's true.
So Python should return.
Let's go to the restaurant.
I run my app and yes that's what I see.
If instead both of the values are true.
So there's value in this value to the Apple step running here because I don't if I if I want to eat
print.
Let's go to the restaurant so python will print this.
And that's it.
The app stops here.
Well it's gonna stop running here but if it's not truthful it's just the way I fight this.
So as you can see it stops here.
But if I want to eat is false.
So in this case by will verify if I want to eat.
No that's false.
I don't want to eat.
So I don't then we'll verify if I want to drink.
And in this case it's is weird.
So it's going to return.
Let's have a drink.
So if we run our app as you can see by then return let's have a drink.
So those are the apps.
Well those are the ways that you guys can use the if statement.
Another thing that you can add to your if statement and that's the last thing that we are gonna talk
about is the not so let's say for example I am using the if statement right here and I want to verify
the reverse so let's say for example if I don't want to eat.
In this case I will simply verify if not.
So if I don't want to eat I want a python to return.
Let's go to the restaurant which doesn't make sense.
Once again it's just for the example.
So let's change the example a bit.
If I don't want to eat I want Python to return I'm good.
Good.
So in this case python will verify if I don't want to eat.
So in this case if I not do so it's going to be the reverse instead of being false.
It's gonna be like if it's true.
So python will verify if it's true
in this case let's write down true.
So what Python will do Python will verify if it's true if it's not true by ton.
Well if it's true it's gonna become false so the only thing that did not do it will simply change the
value here.
So instead of being true it's going to be false.
So Python should return nothing but you can see Python return nothing.
And if it's false false.
And when the python returns I'm good because the only thing that the not will do bio do not value right
here.
I will simply verify if the reverse is true.
So in this case is the reverse.
Well if it's false here it's gonna become true.
And if it's true it's become it becomes false.
All right.
So until now guys you understand the if statement and how it works if you guys still still have problems
with this I suggest you to repeat this class to be able to understand that because once again the if
statement is something that is very very huge in Python and practice it.
So that's the best way for you guys to learn it so you can practice and make make some exercises you
can make exercise about food about colors about anything you want.
I practice it a little bit and you'll see it's not something that is hurt.
It's just about practice.
That's it for this class guys and see in our next class.