if else Statement in Python Programming
In this lesson, we will understand what if else statement is and how it works in Python programming along with some example.
What is if else Statement
In a Python program, the if statement allows us to execute a block of statements when a condition is true. If the condition is false, no action is taken. But what if we want to execute a different block of code when the condition is false? This is where the else statement comes into play. We can use the else statement alongside the if statement to execute a block of code when the condition is false.
if condition:
# code to execute if the condition is true
else:
# code to execute if the condition is false
Unlock This Lesson & Start Learning!
Get full access to this lesson, practical exercises, quizzes, and your Mentora AI Tutor.
Special Offer, use coupon code DWL6BC to get additional discount of 10% on all subscription. Hurry limited time offer.
1 Month
Renews at ₹259/month.
Manual renewal required.
No automatic charges.
- Premium lessons access
- Quizzes and exercises
- Mentora AI Tutor
3 Months
Equivalent to ₹219.67/month.
Manual renewal required.
No automatic charges.
- Premium lessons access
- Quizzes and exercises
- Mentora AI Tutor
6 Months
Equivalent to ₹193.17/month.
Manual renewal required.
No automatic charges.
- Premium lessons access
- Quizzes and exercises
- Mentora AI Tutor
12 Months
Equivalent to ₹179.92/month.
Manual renewal required.
No automatic charges.
- Premium lessons access
- Quizzes and exercises
- Mentora AI Tutor