CONDITIONS IN PYTHON
Conditions in Python or Conditional statements are used to perform decision making challenges. In this tutorial, we will learn how to run block of code with if, else and else if statements. We will be thoroughly checking particular conditions.
Statement | Function |
---|---|
If Statement | This statement is use to check whether the condition is true or not, if the condition is true then the code is executed. |
If Else Statement | This statement is use to check whether the condition is true or not however if the condition doesn't meet the criteria then the else statement gets executed. |
Else - If Statement | It is similar to the if else statement but it allows us the freedom of executing multiple else if blocks to check as many blocks of code we want |
Conditions in Python: If Statement
Syntax:
if expression: statement
If the expression returns True, then the block code (conditional statement) runs, if the statement is false, the expression is returned False and the program ends without running the conditional statement. These type of conditions in python is used when you want an immediate logic out of an if-else block.
Conditions in Python: If-Else Statement
Syntax:
if expression: statement else: statement
This statement is use to check whether the condition is true or not however if the condition doesn’t meet the criteria then the else statement gets executed.
Else-If Statement
Syntax:
if expression1: statement elif expression2: statement elif expression3: statement else: statement
It is similar to the if else statement but it allows us the freedom of executing multiple else if blocks to check as many blocks of code we want