1 Python range

1. What is range()?

range() is used to generate a sequence of numbers.

In simple words:
👉 range() gives numbers one by one
👉 It is mostly used with loops

2. Simple range() Example

Example


 

Output:


 

👉 Starts from 0 by default.

3. range(start, stop)

Example


 

Output:


 

👉 stop number is not included.

4. range(start, stop, step)

Example


 

Output:


 

5. range() with While Loop

Example


 

👉 range() logic done manually.

6. Convert range to List

Example


 

Output:


 

7. range() with Negative Step

Example


 

Output:


 

8. range() with Length

Example


 

9. range() in Real Programs

Example: Table of 2


 

10. Common Beginner Mistakes

❌ Expecting Stop Value Included


 

👉 5 is not included.

❌ Using Zero Step


 

❌ Error.

11. Simple Practice Examples

Example 1: Even Numbers


 

Example 2: Countdown


 

Example 3: Sum of Numbers


 

12. Summary (Python range())

✔ Generates number sequence
✔ Used mainly with loops
✔ Stop value is not included
✔ Supports step value
✔ Very useful in loops

📘 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

  • Comprehensions

  • Mini Python Projects

Just tell me 😊

You may also like...