Processing Math: Done
No jsMath TeX fonts found -- using unicode fonts instead.
This may be slow and might not print well.
Use the jsMath control panel to get additional information.
jsMath Control PanelHide this Message


jsMath
Differences between revisions 3 and 4
Revision 3 as of 2019-10-31 05:55:55
Size: 758
Editor: vdelecroix
Comment:
Revision 4 as of 2019-10-31 05:56:36
Size: 785
Editor: vdelecroix
Comment:
Deletions are marked like this. Additions are marked like this.
Line 26: Line 26:
The iterator `xrange` is no longer valid in Python 3. The iterator `xrange` is no longer valid in Python 3 simply use `range` instead.

Warning:

Starting from version 9.0, the default distributed version of Sage is using Python 3. See Python3-Switch for more information.

Main caveat

range and xrange

In Python range is a function that returns a list.

Toggle line numbers
   1 sage-8.9: range(5)
   2 [0, 1, 2, 3, 4]
   3 sage-8.9: type(range(5))
   4 <type 'list'>

In Python 3, range is an object that somehow behave as a list (ie elements can still be acessed with square bracket, it has a length, etc) but it is not a list.

Toggle line numbers
   1 sage-9.0: range(5)
   2 range(0, 5)
   3 sage-9.0: range(5)[2]
   4 2
   5 sage-9.0: range(5)[1::2]
   6 range(1, 5, 2)
   7 sage-9.0: type(range(5))
   8 <class 'range'>

The iterator xrange is no longer valid in Python 3 simply use range instead.

Python3-user (last edited 2020-01-02 08:29:00 by chapoton)