- This event has passed.
Python Conditional Statement
May 7, 2024 @ 8:00 am - 5:00 pm
What is a Conditional Statement?
- Decision making statements in programming languages decides the direction of flow of program execution.
- Decision making statements available in python are also known as if..else statement
VERSION OF IF ..ELSE STATMENT
- if statement
- if..else statements
- nested if statements
- Short Hand if-else statement
IF STATEMENT
- It is used to decide whether a certain statement or block of statements will be executed or not.
if condition:
# Statements to execute if
# condition is true
IF- ELSE
- The elsestatement with ifstatement to execute a block of code when the condition is false.
- if (condition):
- # Executes this block if
- # condition is true
- else:
- # Executes this block if
- # condition is false
IF-ELIF-ELSE
- The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed.
- If none of the conditions is true, then the final else statement will be executed.
- if (condition):statementelif (condition):
statement . .
else: statement
NASTED- IF
- Python allows us to nest if statements within if statements.
if (condition1):
# Executes when condition1 is true
if (condition2):
# Executes when condition2 is true
SHORT HAND IF -ELSE STATEMENT
- statement_True if condition else statement_False
This can be used to write the if-else statements in a single line
