why won't slicing lists raise IndexError?

Jason Maldonis jjmaldonis at gmail.com
Mon Dec 4 15:13:53 EST 2017


>
> Have you ever used a language that does that?

I have.
> The String class in the C# language does that, and it's /really/ annoying.
> I have to add extra code to prevent such exceptions.
> In practice, I find that the way that Python does it is much nicer. (And
> Python isn't unique in this respect, either.)
>

I'm not here to criticize one way or the other, just understand. As far as
I'm aware, I don't rely on python's slicing functionality allowing indexes
that are over the length of a list. But I'm just one person and I'm sure
there are many other use cases I'm not thinking about. If you think what
you wrote is a good explanation for why slicing doesn't raise IndexErrors
in python, I'd be interesting in seeing some of your use cases about when
you had to explicitly check bounds of list slices in C#.



More information about the Python-list mailing list