Ends in 7 days

BLACK FRIDAY: Receive 83% off Programiz PRO

+🎁 Buy 1 year, gift 1 year FREE — Split with a friend for just $49.50 each

Start FREE trial →
Background Image

Buy 1 year, Gift 1 year —completely FREE

Start FREE trial →
Keshava Harshith Manikyala
last year
Keshavacountry asked

Example if I create a range(1,7) at list(). then o/p is "[1,2,3,4,5,6]" why here '7' is ignored is it using the indexing count.

Kelish Rai
Expert
last year
Kelish Rai answered

When you do range(1, 7), it gives you numbers starting from 1 up to but not including 7. So it stops at 6.

It’s not about indexing exactly — that’s just how range() works in Python. The second number is treated as the "stop point", and it’s excluded from the result.

Let me know if you need more explanation on this. I'm happy to help.

Python
This question was asked as part of the Learn Python Basics course.