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

Timeline for answer to Why are Python's slice and range upper-bound exclusive? by RARE Kpop Manifesto

Current License: CC BY-SA 4.0

Post Revisions

7 events
when toggle format what by license comment
Jul 27, 2025 at 22:40 comment added RARE Kpop Manifesto @Barmar another really weird aspect about exclusive ranges is that when slicing something, my_arr[3] gets you 1 item but my_arr[3:3] gets you nothing.
Jul 27, 2025 at 22:31 comment added RARE Kpop Manifesto @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)
Jul 25, 2025 at 12:52 comment added Barmar 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.
Jul 25, 2025 at 5:07 comment added RARE Kpop Manifesto @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
Jul 25, 2025 at 4:54 comment added RARE Kpop Manifesto @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.
Jul 22, 2025 at 15:13 comment added Barmar This doesn't answer the question about why ranges are like this, it's a rant suggesting they shouldn't be.
Jul 22, 2025 at 13:25 history answered RARE Kpop Manifesto CC BY-SA 4.0