+ 8

list1 = range(5) is [0,1,2,3,4] and list2 = range(10) is [0,1,2,3,4,5,6,7,8,9] according to the provided example. So, why does list1 index[4] not result in the answer 3?

2nd Nov 2016, 9:17 PM
johnathen
8 ответов
+ 9
Indexes start at 0. list1[4] is thus the 5th element of list1, ie 4. Same deal for strings.
2nd Nov 2016, 9:37 PM
Zen
Zen - avatar
+ 3
i have learned that counting lists and strings works differently. i now understand why the answer is 4.
2nd Nov 2016, 9:23 PM
johnathen
+ 1
all indexes start with '0' like: [0,1,2,3,4] |0,1,2,3,4|
27th Feb 2017, 5:08 PM
LT Geimeris
LT Geimeris - avatar
0
Thanks you all for the replies to johnathen, They solved also my doubt.
4th Nov 2016, 8:28 PM
Manuel Salvador González
Manuel Salvador González - avatar
0
thank you for your help. by the way, Python is awesome!
4th Nov 2016, 8:39 PM
johnathen
0
Range elements count start from 1 and Index count start from 0.
30th Nov 2016, 11:03 AM
Ahasan Al Rabbi
Ahasan Al Rabbi - avatar
0
coz are like array in Java de start counting with 0 not 1
6th Dec 2016, 9:21 PM
ABDULLAHI JAFAR MUSA
0
all indexes start with '0' like: [0,1,2,3,4] |0,1,2,3,4|
27th Feb 2017, 5:08 PM
LT Geimeris
LT Geimeris - avatar