why won't slicing lists raise IndexError?

Ned Batchelder ned at nedbatchelder.com
Tue Dec 5 06:31:54 EST 2017


On 12/4/17 10:41 PM, Rick Johnson wrote:
>> I think we've demonstrated the slicing semantics well.
> Indeed. And i never questioned this aspect. I merely wanted
> to inform the lurkers that the else-clause was handling a
> non-action, and therefore, could be omitted.

Your original statement sounded like, "The else clause can never be 
executed," which would have been in direct opposition to the point, that 
slicing outside the limits would produce an empty list, not an 
exception.  I'm not sure why you are certain that there's never a reason 
to execute code in that case.

Perhaps I have a simulation on a conceptually infinite line, but only 
store the actual points needed.  The "non action" would be to extend the 
line.

--Ned.



More information about the Python-list mailing list