Range definition -needs correction | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Range definition -needs correction

Range(10) generates all the integer numbers from zero up to, BUT NOT INCLUDING 10. Description NEEDS CORRECTION. I.e. list (Range(N)) is [0, 1, ..., N-1]

12th May 2018, 10:49 AM
Stoyan
5 Answers
12th May 2018, 10:51 AM
🌛DT🌜
🌛DT🌜 - avatar
+ 2
range definition is correct :D range() (and Python in general) is 0-index based, meaning list indexes start at 0, not 1. eg. The syntax to access the first element of a list is mylist[0]. Therefore the last integer generated by range() is up to, but not including, stop. For example range(0, 5) generates integers from 0 up to, but not including, 5.
12th May 2018, 10:54 AM
MsJ
MsJ - avatar
+ 2
yes, that one, and the next with two arguments. ît includes the first argument, but then UP TO BUT NOT INCLUDING THE SECOND
12th May 2018, 10:55 AM
Stoyan
+ 1
ok I explain you this by making an list x=[1,2,3,4,5] the length of this list is 5 but to access fifth element we do like this x[4] which indicates to 5th element it is because index start with 0 so 0 1 2 3 4 this is called as range (0,5) in counting they are 5 but it start from 0 so it not included the last 5
12th May 2018, 11:01 AM
MsJ
MsJ - avatar
+ 1
I understand and only trying to help you teach what you just wrote. People are learning Python here, me too, and when you say Range(10) produces all the numbers up to 10, without qualification, most people would understand INCLUDING 10.
12th May 2018, 11:03 AM
Stoyan