 Hello everybody. Today we're going to be taking a look at the if statement within Python. Now it's actually the if Elif El statement, but that's a mouthful. So I'm just going to call it the if El statement. Now we have this flow chart and I apologize for being blurry, but this is the absolute best one that I could find. Right up top we have our if condition. Now if this if condition is true, we're going to run a body of code. But if that condition is false, we're going to go over here and go to the Elif condition. The Elif condition or statement is basically saying if the first if statement doesn't work, let's try this if statement. If this Elif statement is true, it goes to this body of code. If it's false, it'll come over here to the else. And the else is basically if all of these things don't work, then run this body of code. Now you can have as many Elif statements as you want, but you can only have one if statement and one else statement. So let's write out some code and see how this actually looks. Let's first start off by writing if that is our if statement. And now we have to write our condition, which is about to be either met or not met. So we'll say if 25 is greater than 10, which is true, we'll say colon, and then we're going to hit enter. And it's going to automatically indent that line of code for us. And this is our body of code. So if 25 is greater than 10, our body of code will execute. So for us, we're just going to write print, and we'll say it worked. Now if we run this, it's going to check is 25 greater than 10, if that is true, print this. So let's hit shift, enter, and it worked. Now let's take this exact code, paste it right down here, and we'll say is less than. And right now, this if statement is not true. So it's not actually going to work. As you can see, there's no output. There's nothing that happened really, but it did check to see if 25 was less than 10, but it just wasn't true. Now we can use our else statement. So we're going to come right down here, and we're going to say else, and we'll do a colon, and we'll hit enter again, automatically indenting. And we're going to say print. And we're going to say it did not work dot, dot, dot. So what it's going to do is it's going to come up here and check is 25 less than 10. No, it's not. So this body of code is not going to be executed. It's going to go right down to this else statement. Now this else statement is going to be printed. There's no condition on this. So the if statement has a condition, 25 is less than 10. This has no condition. So if this doesn't work, if this is false, it's going to come down here and it will run this body of code. Let's run this by clicking shift enter. And as you can see, our output is it did not work. Now let's go back up here and put greater than because this is now true. It's going to say if 25 is greater than 10, print it worked. And then it's going to stop. It's not going to go to this else statement at all. So let's run this. And our output is it worked. So what if we have a lot of different conditions that we want to try? Let's come right down here. This is where the LF comes in. So really quickly, let's change this to a not true a false statement. We're going to go down and say LF. And we're going to say if it is, and let's say 30, we'll say LF worked. So now it's going to check is 25 less than 10? No, it's not. Let's look at the next condition is 25 less than 30. And if it is, we'll print LF worked. So let's try running this. And LF worked. Now we can do as many of these LF statements as we want. We can do let's just try a few of them right here. So we'll say if 25 is less than 20 is less than 21. And let's do 40. And let's do 50. So we'll say LF, LF two, three, and LF four. Now if you look at this, the first one that is actually going to work is this 25 to 40 right here. Once this one is checked and it comes out as true, none of the other LF or L statements will work. So let's try this one. It should be LF three. And this one ran properly. Now within our conditions so far, we've only used a comparison operator. We can also use a logical operator like and or or. So we can say if 25 is less than 10, which it's not, let's say or actually, and we'll say or one is less than three, which is true. If we run this, now it will actually work. So we can use several different types of operators within our if statement to see if a condition is true or not or several conditions are true. There's also a way to write an if else statement in one line if you want to do that. So we can write print, we'll say it worked. And then we'll come over here and say if 10 is greater than 30. And then we'll write else print. And we'll say it did not work. Just like we had before, except now it's all occurring on one line. So let's just try this and see if it works. So it's saying print it worked if 10 is greater than 30, which it wasn't. So it went to the else statement. And then it printed out our body right here, although we didn't have any indentation or multiple lines, it was all done in one line. Now there's one other thing that we haven't looked at yet. And I'm going to show it to you really quickly. And that's a nested if statement. So when we run this, it's going to say it worked. It works because it says 25 is less than 10, or one is less than three. Since this is true, it's going to print out it worked. But we can also do a nested if statement. So we can do multiple if statements as well. So we're going to hit enter. And we'll say if, and we'll do a true statement here. So we'll say if 10 is greater than five, let's do a colon hit enter. And then we'll say print. And then we'll type a string saying this nested if statement. Oops, worked. Now let's try this out and see what we get. So it went through the first if statement, it said it was true and it prints out it worked. This is still the body of code. So it goes down to this next if statement. And it says if 10 is greater than five, we're going to print this out. And you could do this on and on and on, it can basically go on forever. And you can create a really in depth logic. And that actually happens a lot when you start writing more advanced code. So I hope that this was helpful. I hope that you understand the if else statement better. I hope that you understand how nested if statements work as well. Thank you guys so much for watching. If you liked this video, be sure to like and subscribe below and I'll see you in the next video.