+ 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.
8 odpowiedzi
+ 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.
+ 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.
+ 2
nums[4] is the 5th element in the list , therefore the output is 4
+ 2
for range it starts the argument from zero to that argument
0
Pretend their are eleven numbers now including zero.
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
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
0
I am confused. If the list starts from 0 then the fourth element should be 3 and not 4 as the quiz says