numbers = list(range(3, 8)) print(numbers) >>> [3, 4, 5, 6, 7] ... Why is 8 not included there if its a part of the range, yet 3 is included in there? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

numbers = list(range(3, 8)) print(numbers) >>> [3, 4, 5, 6, 7] ... Why is 8 not included there if its a part of the range, yet 3 is included in there?

maybe I'm failing to understand it but is it like that when you range from set number to set number instead of numbers = list(range(8)) print(numbers) >>> [0, 1, 2, 3, 4, 5, 6, 7, 8] help me understand this someone please. thanks.

27th Dec 2015, 12:18 AM
Jorge Montiel
Jorge Montiel - avatar
5 Answers
+ 3
I had the same question as you. I google it, and in the link below there is the logical explanation, why the notation is better. That paper was written by E.W Dijkstra, considered one of the most inffluent people on computer science founding generation. In that paper also explains why is better to start indexing in 0 rather than one. Is amazing!! and it's just a few lines!! http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
30th Dec 2015, 6:23 PM
adrien
+ 2
It is bcoz upper limit is not included and range will give the difference of numbers . mathematically represented as [3,8)
24th Jan 2016, 1:18 PM
Bhaargavi Agrawal
+ 2
range(3,8) represents a range beggining in 3 that has 8-3=5 elements in it: [3,4,5,6,7] hope this helps
11th Apr 2016, 8:48 AM
Diego Yglesias Fedeli
Diego Yglesias Fedeli - avatar
+ 1
I think in the range with the two arguments the first number is a value and the second represent the index of the last element in the range.
1st Dec 2016, 6:20 PM
Michael
Michael - avatar
+ 1
for i in range(a,b) means for i going from a to b for example for i in range(3,8): do somthg i=3 do smthg i=4 do smthg i=5 do smthg i=6 do smthg i=7 do smthg i=8 okay we've reached 8 the loop is done.. we have 'done something' 5 times
9th Jan 2017, 3:07 AM
ramzi
ramzi - avatar