|
Size: 727
Comment:
|
Size: 1211
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 7: | Line 7: |
| In Python `range` is a function that return a list. | In Python `range` is a function that returns a list. |
| Line 11: | Line 11: |
| sage: type(range(5)) | sage-8.9: type(range(5)) |
| Line 15: | Line 15: |
| {{{ | {{{#!highlight python |
| Line 20: | Line 20: |
| sage: range(5)[1::2] | sage-9.0: range(5)[1::2] |
| Line 22: | Line 22: |
| sage: type(range(5)) | sage-9.0: type(range(5)) |
| 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. == strings, unicode and bytes == In Python 2 a chain of characters between simple, double or triple quotes creates an ascii string. To create a unicode string one has to use the prefix `u` (which remains valid in Python 3). In Python 3, a chain of characters between quote will gives rise to a unicode string. To create specifically an ascii string one has to use the prefix `b` (which is already valid in Python 2). |
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.
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.
The iterator xrange is no longer valid in Python 3 simply use range instead.
strings, unicode and bytes
In Python 2 a chain of characters between simple, double or triple quotes creates an ascii string. To create a unicode string one has to use the prefix u (which remains valid in Python 3).
In Python 3, a chain of characters between quote will gives rise to a unicode string. To create specifically an ascii string one has to use the prefix b (which is already valid in Python 2).
