Python Conditional Statements – if, elif and else
Published: 16 Sep, 2026 | Author: CCI Admin | Category: Python / Programming
Programs often need to make decisions based on different conditions. Python provides conditional statements such as if, elif, and else to control the flow of a program.
In this beginner-friendly guide, we will learn conditional statements with simple examples and real-world programming situations.
What Are Conditional Statements in Python?
Conditional statements allow a program to execute different blocks of code depending on whether a condition is true or false.
For example, a program can check whether a student has passed an examination and display an appropriate message.
1. The if Statement
The if statement executes a block of code when a condition is true.
age = 20
if age >= 18:
print("You are eligible to vote")
Since the age is 20, the condition is true and the message is displayed.
2. The if-else Statement
The else block runs when the if condition is false.
marks = 45
if marks >= 40:
print("Pass")
else:
print("Fail")
Here, the program checks the student's marks and displays either Pass or Fail.
3. The elif Statement
The elif statement is used when we need to check multiple conditions.
marks = 75
if marks >= 90:
print("Grade A+")
elif marks >= 75:
print("Grade A")
elif marks >= 60:
print("Grade B")
else:
print("Grade C")
Python checks the conditions from top to bottom and executes the first condition that is true.
Real-World Example – ATM Withdrawal
Conditional statements can be used to make decisions in an ATM application.
balance = 5000
amount = 3000
if amount <= balance:
balance = balance - amount
print("Withdrawal successful")
print("Remaining balance:", balance)
else:
print("Insufficient balance")
This example demonstrates how a program can check a condition before performing an operation.
Real-World Example – Student Result
marks = int(input("Enter your marks: "))
if marks >= 90:
print("Excellent")
elif marks >= 75:
print("Very Good")
elif marks >= 50:
print("Good")
elif marks >= 40:
print("Pass")
else:
print("Fail")
This type of logic is commonly used in student result and grading systems.
Using Multiple Conditions
Python also allows us to combine conditions using and, or, and not.
age = 22
has_id = True
if age >= 18 and has_id:
print("Entry allowed")
else:
print("Entry not allowed")
Why Are Conditional Statements Important?
- They help programs make decisions.
- They control the flow of execution.
- They are useful in real-world applications.
- They help create interactive programs.
- They are important for learning advanced programming concepts.
Common Mistakes Beginners Make
- Forgetting the colon : after the condition.
- Using incorrect indentation.
- Confusing = with ==.
- Writing conditions in the wrong order.
- Forgetting to convert user input into numbers when required.
Faculty Tip from CCI Computer Education
When learning conditional statements, don't memorize only the syntax. Try to convert everyday decisions into programming conditions.
For example: Login → Check username → Check password → Allow or reject access. Practicing these small decision-making problems will make Python programming much easier.
Practice Task
Create a Python program that accepts a student's marks and displays:
- 90–100 → Excellent
- 75–89 → Very Good
- 60–74 → Good
- 40–59 → Pass
- Below 40 → Fail
Try writing the program yourself before checking another solution.
Frequently Asked Questions
1. What is an if statement in Python?
The if statement executes a block of code when a specified condition is true.
2. What is the purpose of elif?
The elif statement allows a program to check additional conditions when previous conditions are false.
3. What does else do in Python?
The else block executes when none of the preceding conditions are true.
4. Can Python have multiple elif statements?
Yes. A Python program can contain multiple elif statements when several conditions need to be checked.
5. What is the difference between = and ==?
The = operator assigns a value to a variable, while == checks whether two values are equal.
Learn Python Through Practical Training
At CCI Computer Education, Pudukkottai, students can learn Python step by step through coding exercises, practical examples, and real-world projects.
After learning conditional statements, students can continue with loops, functions, lists, dictionaries, object-oriented programming, file handling, databases, and Python projects.
Conclusion
Python conditional statements are essential for creating programs that can make decisions. The if, elif, and else statements provide a simple way to control program flow.
Practice small decision-making programs regularly and gradually move toward real-world Python applications.
What's Next?
In the next Python learning topic, we can explore Python Loops – for and while and learn how to repeat tasks efficiently.
Related CCI Blogs
Contact CCI Computer Education – Pudukkottai
Want to improve your Python and programming skills? Join CCI Computer Education, Pudukkottai and learn through practical, step-by-step training.
Call: 98427 97945 | Website: ccipudukkottai.com
CCI Computer Education – Know the Edge of Knowledge