extend
doesn't return a value. Thus, printinga.extend(b)
will beNone
. Thus, if you havea = [5, 6, 7, 8, 9].extend(range(15, 20))
and printa
it will showNone
. A way around it would be to concatenate listsa = [5, 6, 7, 8, 9] + range(15, 20)
[5, 6, 7, 8, 9][2]
- everything is as should be as it starts counting elements from 0. It is not modifying list, it is merely returning a certain element from the list.[5, 6, 7, 8, 7].count(7)
and[5, 6, 7, 8, 7].index(8)
show the expected output. First one is the number of times 7 occurs in the list, second one is an index of number 8 (again, counting starts from 0).
So, all in all the use of hardcoded list behaves as expected in all of the examples you've produced.