[Python-ideas] Should range() == range(0)?
Terry Reedy
tjreedy at udel.edu
Mon May 7 04:43:20 CEST 2012
On 5/6/2012 6:24 PM, Georg Brandl wrote:
> 7. The "default value" is only really useful for types that are best
> described as "data-like".
> range is not a data-like type, it's a helper
> for iteration, just as filter or dictviews aren't data-like.
Not knowning your definition of 'data-like', it is hard to respond.
A range is an immutable, indexable, reiterable sequence of regularly
spaced ints with a definite length. It compactly represents an finite
but possibly long arithmetic sequence. While mostly used for iteration,
it is not limited to iteration. It implements the sequence protocol. It
is not an iterator. It is not dependent on an underlying iterable. It is
properly documented with the other sequence types.
It is most like a bytes object in being an immutable sequence of ints.
In that regard, it is different in not restricting the ints to [0,255]
while restricting the differences to being equal.
(Dict views, especially .keys() are also, to me, somewhat data-like and
not limited to iteration. But, unlike ranges, they are dependencies.)
--
Terry Jan Reedy
More information about the Python-ideas
mailing list