If Statement
if is a Words that are predefined in the programming language. keyword that executes the given code if the specified statement evaluates to True. Below shows how to structure an if statement.
   #do this
The code to be executed if the if statement is true must be indented as shown above.
Below, we will assign two different values to variables a and b and then print a if it is greater than b.
Print variable a if it is greater than variable b
To assign two values to a and b and the print a if it's greater than b, enter the below code into a code editor:
a = 5
b = 3
if a > b:
    print(a)
Output
5
In the code above, we asked if a was greater than b. Since a was indeed greater than b, a was printed.
if-else
else is another keyword that, when combined with if, can perform an operation if the if statement evaluates to False.
In an if-else statement, the program checks to see if the if statement is true. If it is true, the computer performs the if operation. However, if the if statement is false, the program performs the else operation. An if-else statement is structured as shown below.
   #do this
else:
   #do this instead
The code to be executed if the if statement is true must be indented, as does the else code to be executed if the if statement evaluates to false, as shown above.
Below, we will assign two different values to variables a and b and then print a if it is greater than b. Otherwise, we will print b.
Print variable a if it is greater than variable b. Otherwise, print b.
To assign two values to a and b and print a, if it's greater than b, else print b, enter the below code into a code editor:
a = 5
b = 8
if a > b:
   print(a)
else:
   print(b)
Output
8
In this example, the value of b was printed. As a is smaller than b, the first statement evaluated to false, which meant the else statement was performed instead.
Try performing your own if and if-else statements using different conditions.