3 Python For Loops

1. What is a For Loop?

A for loop is used to repeat code for each item in a sequence.

In simple words:
👉 Python takes one item at a time
👉 Runs the code for that item
👉 Stops when items are finished

2. Where Do We Use For Loop?

We use for loop with:

  • Lists

  • Tuples

  • Sets

  • Dictionaries

  • Strings

  • Range of numbers

3. Simple For Loop Example

Example


 

4. For Loop with Numbers (range())

Example


 

Output:


 

Print 1 to 5


 

5. For Loop with String

Example


 

6. For Loop with List

Example


 

7. For Loop with Tuple

Example


 

8. For Loop with Dictionary

Loop Keys


 

Loop Values


 

Loop Key & Value


 

9. For Loop with Condition

Example


 

10. Stop Loop Using break

Example


 

11. Skip One Step Using continue

Example


 

12. For Loop with Else

else runs when loop finishes normally.

Example


 

13. Nested For Loop (Loop Inside Loop)

Example


 

14. Important Rule: Indentation

Python uses spaces to understand loop body.

❌ Wrong


 

✔ Correct


 

15. Common Beginner Mistakes

❌ Forgetting Colon :


 

❌ Using Wrong Variable


 

✔ Correct:


 

16. Simple Practice Examples

Example 1: Print Even Numbers


 

Example 2: Sum of Numbers


 

Example 3: Count Letters


 

17. Summary (Python For Loop)

✔ Used to repeat code
✔ Works with sequences
✔ Cleaner than while loop
✔ Supports break & continue
✔ Very important in Python

📘 Perfect for Beginner eBook

This chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • Break & Continue

  • Loop Exercises

  • Functions

  • Mini Python Projects

Just tell me 😊

You may also like...