Conditional Statements in Python
Decision making is as important as life in any programming language. Decision making in programming languages is automated using conditional statements. Conditional statements evaluate Python to see if it meets the specified conditions. The condition is evaluated and processed as true or false. If this is the case, the program will run as needed. If the condition turns out to be false, the statement following the If condition is executed.
Decision making statements are also called as Conditional Statements.
Get Syed Mohd Nazar Ali’s stories in your inbox
Join Medium for free to get updates from this writer.
In Python there are Six different conditional statements used for Decision making.
- if
- if-elif
- if-else
- if-elif-else
- nested-if
- if statement : if statement is most important for decision making in python , in which first if statement (condition) is executes and if statement is True then block statement is executes , if statement (condition) is False then block statement is not executes.
Statement preceding block generally ends with a colon(:)
if expression:
Statement- if-elif statement : Creating an elif statement is identical to an if statement, with one difference, you use the elif keyword instead. You’re able to have multiple conditions for each elif as well. All elif statements are connected to one original if statement, so that once a single conditional is True, the rest do not run. Let’s try it:
- if-else statement: Like an elif statement, the else clause needs to always be associated with an original if statement. The else clause covers all other possibilities, so you don’t need to write a condition at all; you just need to provide the keyword “else” followed by an ending colon. Remember that an else clause will run the code inside of it if the program reaches the statement. Try the following:
- Nested -if : we can have a if..elif..else…statement inside another statment if..elif..else…statement . In Nested If statements, the indentation (whitespace at the beginning) to determine the scope of each statement should take precedence.








