S
Steve Bergman
A couple of off the wall questions.
It seems to me that there is usually a solid *reason* for things in
Python and I'm wondering about the rationale for the way slicing works:
my_string[2:5]
gets you the 3rd through the 3rd through the 5th character of the
string because indexing starts at 0 and you get everything up to, but
not including the second index.
Why? It doesn't seem intuitive to me. To me, it makes it harder, not
easier, to work with slices than if indexing started at 1 and the
above expression got you the 2nd throught the 5th character.
Another thing that I've been puzzling over is the pow() function.
pow(x,y) gives x**y. Fine.
But pow(x,y,z) gives (x**y) % c
I'm curious to know what the pressing reason for such a feature was.
It seems to me that there is usually a solid *reason* for things in
Python and I'm wondering about the rationale for the way slicing works:
my_string[2:5]
gets you the 3rd through the 3rd through the 5th character of the
string because indexing starts at 0 and you get everything up to, but
not including the second index.
Why? It doesn't seem intuitive to me. To me, it makes it harder, not
easier, to work with slices than if indexing started at 1 and the
above expression got you the 2nd throught the 5th character.
Another thing that I've been puzzling over is the pow() function.
pow(x,y) gives x**y. Fine.
But pow(x,y,z) gives (x**y) % c
I'm curious to know what the pressing reason for such a feature was.