How does [ * : * ] selector works in python lists?

I’ve a basic problem in understanding how python selects elements from below script?

myList = ['a', 'b, 'c', 'd', 'e', 'f', 'g', 'h']
start = 1
end = 5

print myList[ start : end ]

O/P ==> ['b, ‘c’, ‘d’, ‘e’]

During starting point i.e. start = 1 python selects element ‘b’ from the list because ‘b’ item is at 1st index point of list.

But,

For end i.e. end = 5 why python selects element ‘e’, where python index starts from zero, then if we count from zero then fifth index point element should be ‘f’, right?

For end element i.e. end=5, does python starts counting from 1 rather than 0?!

This should help https://stackoverflow.com/questions/509211/understanding-pythons-slice-notation

:slightly_smiling_face:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.