I've very new to python, and am currently toying with pythonD. Could
someone please explain the rationale behind python designers' thinking
in deciding the function "range(1,12)" should return the sequence 1 to
11 rather than the more intuitively-useful 1 to 12??
The range() function maps closely to a very common idiom in c-like languages.
for (i = a; i < b; i++) { do_stuff(i); }
in a C-like language is the same as
for i in range(a, b): do_stuff(i)
in python. Another way to think about it is to notice that if you do range(10), you get exactly 10 items in your list (starting at 0), so going from 0 to n-1 is the correct way to go. Having the "start from zero" case work intuitively is the starting point and being able to specify a different starting value to zero simply generalises on this.
Are you sure you need your range to start at 1? It's a common newbie error to start counting from 1 instead of zero in some places, but I won't accuse you of such an error without seeing more context :-)
HTH
Tim
After downloading the substantial distribution .zip file, I'm intrigued
to find it includes 3 files of identical size and creation date, differing
apparently only in name (python, python2.4 and python24.exe) and each of
exactly 2,597,888 bytes. What possible purpose could be served by such
triplication that couldn't more efficiently be done by other means?
Naive but curious minds wish to know!
--
John Savage (my news address is not valid for email)
--
http://mail.python.org/mailman/listinfo/python-list
-- http://mail.python.org/mailman/listinfo/python-list