1. Python if Statement
The single if statement is used to execute the specific block of code if the condition evaluates to true. In the case of false output, nothing will execute. Syntax:
Example 1:
Example 2:
2. Python if-else Statement
The if and else statement is used to execute the specific block of code for true condition and another block of code on false condition. Syntax:
Example: Assinged a value to var variable, Now test if the assigned value it greated than 100. As per below code the result will be “Assigned value is greater than 100”.
3. Python if-elif Statement
The if and elif (known as else-if) statement is used to execute the specific block of codes with multiple conditions. In this, if the main if the condition goes false then another elif condition is checked. You can define a number of elif conditions as per your requirements. Syntax:
Example: Taken a avalue as input in total variable. Now compare the value with multiple levels and print the appropriate output.
4. Python Nested if Statement
The nested if statements is use as if inside if. In this if any if condition evalutes to true then it goes to inner if condition. Syntax:
Example: taken 3 numeric inputs and find the greatest value. Like if var1 is greater than var2 then it check if var1 is also greater than var3.