Hello everybody and welcome back to this tutorial. And let us introduce ourselves
with a new thing that we are going to learn right now which is the if
statement in Python 3. Now this is the first actual kind of a loop that we are
going to do, and basically this is really important so make sure to pay attention.
It is not that hard, especially this tutorial which is going to be just the
basic stuff for the if statement. In the next two tutorials we're also going to
cover the if-else statement, and the if-else statement with multiple else if
statements, if you understood what I'm saying. But for now let us just cover the
if statement only. So open up your IDLE as usual, and right here, basically, we can
just try to perform the simple if-else statement, or just the if-statement in this
tutorial. So, if you just type here if, you can see it also already gets flagged as
a word that comes in Python, so it already gets color. So if, what this
basically does is it will look like this, so if something, now of course we don't
have variables something but we'll just use it just for the demonstration
purposes, if something equals to something, two dots, then you need to tab
the next line, as you can see it tabs by default, do something. And we can see
invalid syntax of course because this is not something that actually exists, but
this is the basic idea behind the if statement. So, for example, we can do
something like this, a =3, b =3. And we can just try to do
like this, so if a == b:, make sure to tab everything
in because if you don't tab it in, which the actual interpreter in Python 3
does by default, but if you're using some text editor and you don't tab it in it
will not be considered as a part of the actual if statement. So, if
a == b:, print(), and we can print basically anything we
want, we can print('These 2 values are the same!'). You just press
here enter once again, and you can see right here we get printed out These 2
values are the same! But let's see what happens once actually b is not
equal to a. So a = 3, b = 4, and we will do basically the same
thing. So if a == b, and we will print the same string, so 'These 2
values are the same!' And if I
just press here enter once again, you can see right now nothing gets gets printed
out. So this is an if statement. It is only used once something is equal to
something or when some statement is fulfilled, such as in the first example
right here, a was equal to b, therefore we did this. Now of course this is not
really that useful of an example. What you want to do in a real life program is
basically you want to do some useful tasks once a equals to b, for example. So
let's do something like this, so let's
set a= 5, b = 5. And if a == b we can
do something like this, a = a*b, which will basically make a after
this if statement to be equal to 25. So we can do it like this,
press here enter, our if statement has finished. And if you just type here a you
can see right now a is no longer 5, a is right now 25. So, let me just check
right here. You don't really need to use always this ==, you can use
something like this, so if b is smaller than a, which currently it is since a is
25, you can print(
'b is smaller than a'), close the actual bracket right here, press ENTER,
and we get printed out b is smaller than a. So this is basically a simple
example of the if statement. What we are going to do in the next video is
basically cover the if-else statement, which is going to add another statement
in case that this one is not fulfilled. So, for example, imagine if this is not
fulfilled then we need to do something else, and that else will be in an if-else
statement. So hope you enjoyed this tutorial and I hope I see you in the
next one. Bye!