Bruce Leban schrieb am Mi, 12. Okt 2011, um 11:30:17 -0700:
Other than unit testing, what are the use cases? If I was writing a unit test, I'd be inclined to be very explicit about what I meant r1 is r2 repr(r1) == repr(r2) list(r1) == list(r2)
Even with a useful '==' operator defined, you could still use 'r1 == r2' or 'r1 is r2', depending on the intended semnatics, just as with every other data type. You just wouldn't need to expand the range to a list.
Comparing the representations doesn't ever seem useful, though. The only way to access the original start, stop and step values is by parsing the representation, and these values don't affect the behaviour of the range object in any other way. Moreover, they might even change implicitly:
>>> range(5, 10, 3) range(5, 10, 3) >>> range(5, 10, 3)[:] range(5, 11, 3)
I can't imagine any situation which I would like to consider the above two ranges different in.