[Tutor] get (x)range borders

Alan Plum alan.plum at uni-koeln.de
Thu Jan 28 13:37:28 CET 2010


On Do, 2010-01-28 at 12:16 +0100, spir wrote:
> Is there a way to retrieve an (x)range's borders?
> (Eg if I want to print out "m..n" instead of "xrange(m, n)".)

You mean like this?

>>> m = 20
>>> n = 30
>>> a = xrange(m, n)
>>> a
xrange(20, 30)
>>> a[0]
20
>>> a[-1]
29

Please note that the border will always be one step off if you're
looking for the values you originally provided: the endpoint is always
given as exclusive.

If you want to know the step, you probably need to calculate it:

>>> a = xrange(20, 30, 2)
>>> step = a[1] - a[0]
>>> step
2


Cheers,

Alan Plum



More information about the Tutor mailing list