Ifelse_Notes
Ifelse_Notes
Conditional statements in Python play a key role in determining the direction of program execution.
Among these, If-Else statements are fundamental, providing a way to execute different blocks of code
based on specific conditions. As the name suggests, If-Else statements offer two paths, allowing for
different outcomes depending on the condition evaluated.
Python If Statement
The if statement is the most simple decision-making statement. It is used to decide whether a certain
statement or block of statements will be executed or not.
Flowchart of If Statement:
Here, the condition after evaluation will be either true or false. if the statement accepts boolean values
– if the value is true then it will execute the block of statements below it otherwise not.
if condition:
# Statements to execute if
# condition is true
The if statement alone tells us that if a condition is true it will execute a block of statements and if the
condition is false it won’t. But if we want to do something else if the condition is false, we can use the
else statement with the if statement Python to execute a block of code when the Python if condition is
false.
Syntax of If Else in Python:
if (condition):
# Executes this block if
# condition is true
else:
# Executes this block if
# condition is false