1 Python If Statement
1. What is an If Statement?
An if statement is used to make decisions in Python.
In simple words:
👉 Python checks a condition
👉 If the condition is True, Python runs the code
👉 If the condition is False, Python skips it
2. Simple If Statement
Example
👉 Output will appear only if the condition is true.
3. How If Statement Works
-
Python reads the condition
-
If the condition is
True→ code runs -
If the condition is
False→ code does not run
4. If Statement with Comparison Operators
Example
5. If Statement with Boolean Value
Example
6. If Statement with String Comparison
Example
7. Multiple Conditions Using and
Example
8. Multiple Conditions Using or
Example
9. Nested If Statement
An if inside another if is called nested if.
Example
10. Important Rule: Indentation
Python uses indentation (spaces) to understand blocks.
❌ Wrong
✔ Correct
11. Common Beginner Mistakes
❌ Using = Instead of ==
❌ Forgetting Colon :
12. Simple Practice Examples
Example 1: Check Number Positive
Example 2: Check Password
Example 3: Check Even Number
13. Summary (Python If Statement)
✔ Used for decision making
✔ Runs code only if condition is true
✔ Uses comparison operators
✔ Indentation is very important
✔ Very useful in real programs
📘 Perfect for Beginner eBook
This chapter is ideal for:
-
Python beginner books
-
School & college students
-
Self-learners
If you want next, I can write:
-
If–Else Statement
-
Elif Statement
-
Nested If–Else
-
If Statement Exercises
Just tell me 😊
