"Steve Bergman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >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
Yes, see below. > 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? len(s[2:5])== 5-2 s[2:5] + s[5:7] == s[2:7] > 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 you obvious meant (x**y) % z > > I'm curious to know what the pressing reason for such a feature was. Such exponential remainders are used in cryptography work, for instance, with fairly large values, and can be efficiently computed, especially in C, *without* computing a humongous x**y intermediate value. Since this is an int function, it does not really belong in the floating point math module. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list