Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 1
    This doesn't answer the question about why ranges are like this, it's a rant suggesting they shouldn't be. Commented Jul 22, 2025 at 15:13
  • @Barmar @Barmar : that was my point - a language shouldn't be self-inconsistent with one part of it using half-open intervals while other parts use closed-only - like https://code.activestate.com/recipes/579000-equally-spaced-numbers-linspace/ directly recommended by python's documentation (https://docs.python.org/3/library/stdtypes.html#truth-value-testing) : the template code listed is inclusive ranges to emulate range() for floats - so python's own documentation talks about half-open ranges, while simultaneously pointing you to another resource that uses inclusive ranges. Commented Jul 25, 2025 at 4:54
  • @Barmar and that's exactly my point - closed-ranges never face this issue - as long as the supplied bookending values are contextually valid, then the requested range of values can be iterated upon. Half-open intervals half the time easily leads to a self-contradicting paradigm. Heck, even just to describe all 256 bytes, I've seen parts of python's doc where one page describes it as 0 <= byte < 256 then another says 0 <= byte <= 255 - a physical manifestation of said paradigm. I'm fine if they use either one, but at least make it consistent even within just the core lang docs themselves Commented Jul 25, 2025 at 5:07
  • Saying it shouldn't be doesn't explain why it is. Anyway, the logic is that slices should concatenate properly. l == l[:n} + l[n:] without requiring you to explicitly add/subtract from the endpoints. And for i in range(len(l)) should iterate over all the indexes of the list. Commented Jul 25, 2025 at 12:52
  • @Barmar yea i just think it's really awkward if you wanna iterate unsigned byte ordinals in descending order and have to use a signed stop value ::: range(255, -1, -1) Commented Jul 27, 2025 at 22:31

lang-py