Hey, hello again. In this lecture you're going to learn about conditionals. What is a conditional?
Well a conditional is a block of code which performs different actions depending on
whether a given conditional evaluates to true or false so let's go ahead and
create a conditional in Python. I'll create the file conditionals dot py and let me
create a conditional block, and first of all let me create a variable. Let's say a
equals five and here I'll create a conditional block. This block, what this
will do is it will perform an action if a is less than five and another action
if a is equal or greater than five so let me create that. If this, our
conditional starts if a and let's say less than five print, let's say less than 5.
Press ENTER and if you want to perform more actions with this conditional, with
this condition so when this condition is true this will be executed but if you
want to perform more actions you can add one there, if not then you can go to the
next check. So that would be else, so you have a
column here, a column there, so else print equal or greater than 5. Now let me
execute it. And we get equal or greater than 5. So why did you get that? Well
because you know if a is less than 5 which is not, so this evaluates to false,
that means with this this will not be executed so Python will skip this line
and it will go to the next one. This next line says else, so else means if this
is not true, this will be executed, so equal or
greater than five, so in this case if a is not less than five then there's no
other option but a is either equal or greater than five, so that's an if and else
conditional block. However if you want to add more conditions there
you want to use elif, so let's do that the first two lines stay the same. If a
is less than five print less than five elif a is equal to five print equal to
five else print greater than five. Save and execute and you get equal to five.
If a was six, you'd get greater than five and if a was
three you'd get less than five. That's a conditional block in Python and
yeah, try to get familiar with the syntax and in the next lecture I'm going to
incorporate a conditional with this block of code, so see you there.