2.4.1.4 if-elif-else Statement
Python Programming
The if-elif-else statement allows us to check multiple conditions and execute different blocks of code for each condition.
python
# Syntax of if-elif-else statement
if condition1:
# code to run if condition1 is true
elif condition2:
# code to run if condition2 is true
else:
# code to run if none of the conditions are trueExample
python
weather = "cloudy" # The output depends on the value stored in the variable” weather”
if weather == "sunny"