On Monday 10 November 2008, Nasser Abbasi wrote: > Hello; > > I was just browsing something to learn about sage, and noticed this on > this web site > http://wiki.sagemath.org/sage_mathematica > > where it says: > > "sage: [f(i) for i in range(1, 11)] > [g(1), g(2), g(3), g(4), g(5), g(6), g(7), g(8), g(9), g(10)] > > (note that the endpoint of the range is not included). " > > The above struck me as something that would be confusing and will lead > to many programming errors. I do not program in Python and played > with sage very little. But it seems (to me) strange that when one > write range(i,j) that the sequence will stop at j-1. > > Do other who worked with sage more not find this is a bit odd?
This is a standard Python feature. Moreover, it is pretty standard in CS to have constructs like this, because "we" tend to count from zero: many people write C (or Java or ....) loops like this: for(i=0; i<n; i++) { C[i] = A[i] + B[i]; } This loops n times but from 0 to n-1. Same goes for range(n). Changing this convention would break many many packages. If you really want [1..20] then you can write that: sage: [1..20] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] Note however, that this is NOT valid Python and ONLY works on the Sage command prompt and in the notebook. It will not work as library code. Cheers, Martin -- name: Martin Albrecht _pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99 _www: http://www.informatik.uni-bremen.de/~malb _jab: [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---