+ 23

why 4 and not 3

I guess I was half expecting the answer to be 3 and not 4. since the range would be 0,1,2,3,4. I thought nums[4] would mean the fourth item which would be 3. if you know what I mean.

12th Oct 2016, 11:47 PM
Nicholas Riorden
Nicholas Riorden - avatar
8 Antworten
+ 12
nums[4] is the item at index 4, not count 4. Index numbering starts at 0 (an offset, while counting tends to start at 1, a quantity). >>> print(list(reversed(range(5)))) [4, 3, 2, 1, 0] In this example (reversed to more clearly separate indexes, counts and values), the value at list index 1 (counting 2 from the left, from index 0 to 1) is 3.
13th Oct 2016, 1:09 AM
Kirk Schafer
Kirk Schafer - avatar
+ 4
I just tried it with print(nums[0]) and it returned a value of 0. So with range, the first item in the range starts at 0 (not 1 like in a list of strings). My theory at least.
20th Oct 2016, 8:04 PM
Victor Betts
Victor Betts - avatar
+ 2
nums[4] is the 5th element in the list , therefore the output is 4
23rd Nov 2016, 7:48 PM
NeverForEver
+ 2
for range it starts the argument from zero to that argument
11th Feb 2017, 9:24 PM
Gilbert Akwaboah
Gilbert Akwaboah - avatar
0
Pretend their are eleven numbers now including zero.
15th Jan 2018, 10:20 AM
Jesse3021
0
No estoy seguro, pero el conteo de la funcion siempre empieza en 0, pero las listas empienzan en 1 o en 0, para este caso empezo en 0, pero en los quiz anteriores empezaba en 1, por lo que a nuestro conteo se le restaba 1 con respecto a la lista
23rd Oct 2018, 2:41 AM
Antonio Ali Cardoza
0
I'm not sure, but the count of the function always starts at 0, but the lists start at 1 or at 0, for this case it started at 0, but in the previous quiz it started at 1, so our count was subtracted 1 with respect to the list
23rd Oct 2018, 2:42 AM
Antonio Ali Cardoza
0
I am confused. If the list starts from 0 then the fourth element should be 3 and not 4 as the quiz says
1st Jan 2019, 3:26 AM
Manoj Ramachandran
Manoj Ramachandran - avatar