6

I see in the code on this Sage wiki page the following code:

@interact
def _(order=(1..12)):

Is this (1..n) syntax unique to Sage or is it something in Python? Also, what does it do?

exupero
  • 9,136
  • 8
  • 47
  • 63

4 Answers4

13

It's Sage-specific. You can use preparse to see how it is desugared to:

sage: preparse("(1..12)")
'(ellipsis_iter(Integer(1),Ellipsis,Integer(12)))'

See here for documentation of ellipsis_iter, here for information on the preparser.

sdcvvc
  • 25,343
  • 4
  • 66
  • 102
10

There was a Python PEP to add this notation to Python, but it was rejected. Robert Bradshaw decided to implement it anyways, but for the Sage preparser. He implemented the following:

  • (a..b) -- like xrange, so an iterator

  • [a..b] -- list, including endpoints

  • [a,b,..,c] -- arithmetic progression

William Stein
  • 2,465
  • 1
  • 18
  • 12
1

This is not Python syntax. I would guess that it creates a range from 1 to 12.

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
0

(1..n) syntax does not exist in Python.

Delan Azabani
  • 79,602
  • 28
  • 170
  • 210