Python If...Else Statements

Python if and else statements are dicision statements.
You can use these statements where you want to execute something where one condition is true and something different when the condition is false.
World fist Artificial assistant is also built using if else statements.
None: When you use if else statements keep in mind to use indentation.

For example:
                      
        i = 1
        if i==1:
            print("Hello you are in if")
        else:
            print("you are in else")
                      
Output: Hello you are in if

                    

If...elif...else statements

Python elif statement is used when we have multiple conditions.
We can use any number of elif statement.

For example:
                      
        i = 2
        if i==1:
            print("Hello you are in if")
        elif i==2:
            print("Hello you are in first elif")
        elif i==3:
            print("Hello you are in second elif")
        else:
            print("you are in else")
                      
Output: Hello you are in first elif

                    

If statement

We can also use single if statement without else or elif.

For example:
                      
        i = 1
        if i==1:
            print("Hello you are in if")
        
                      
Output: Hello you are in if