PEP 204 - Range Literals: Getting closure

Comparing range literals of other languages:

Python

range(1, 10, 2)

Ruby (dots are arguably reversed and step is a method)

(1..9).step(2)
(1...10).step(2)

Rust (step is a method)

(1..10).step_by(2)

Perl (no step support)

(1..9)

Haskell (step is done by subtracting next element from first: 3 - 1 = 2)

[1,3..10]

Scala (words can make it longer than just calling Range)

1 to 9 by 2
1 until 10 by 2

Julia and Matlab (step in the middle)

1:2:9

R (no step support)

1:9

Swift (explicit dots, but no step support)

1..<10
1...9

Some options for consideration:

Using dots seems complicated because of Ellipsis, but I could be wrong (e.g. this is already valid Python ....__class__)

start:stop:step	   # Used in Python slices and several languages
start..stop..step  # Used in a many other languages, missing the step part
start->stop->step  # Uses an existing token. Sense of direction
start=>stop=>step  # Similar to existing token, might confuse >= <=
start:>stop:step   # Sense of direction, except for step
4 Likes