2 answers

7-8 times out of 10 in Sage you don't want to use range, which is a Python function, and returns Python ints. All the fun stuff lives in the Sage Integer type, and only some functions coerce. You can get a Sage Integer by using srange/sxrange instead of range/xrange: