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 2 and 4 (spanning 2 versions)
Revision 2 as of 2016-05-24 12:40:03
Size: 638
Editor: chapoton
Comment: formatting
Revision 4 as of 2016-05-24 12:42:15
Size: 660
Editor: chapoton
Comment:
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
In version 7.2, SageMath is using the Python 2 syntax. It may soon switch to the Python 3 syntax, where print is a function. In version 7.2, SageMath is using the Python 2 syntax for print. It may soon switch to the Python 3 syntax, where print is a function.
Line 7: Line 7:
||<#FFFF66>To convert from Python 2 to Python 3, you basically need to add parentheses, and write '''print("x")''' instead of '''print "x"'''.|| ||<#FFFF66>To convert '''print''' from Python 2 to Python 3, you basically need to add parentheses, and write '''print("x")''' instead of '''print "x"'''.||

Behaviour of print

The behaviour of print differs in Python 2 and in Python 3.

In version 7.2, SageMath is using the Python 2 syntax for print. It may soon switch to the Python 3 syntax, where print is a function.

To convert print from Python 2 to Python 3, you basically need to add parentheses, and write print("x") instead of print "x".

Here is a conversion table to help you adapt your code:

Python 2

Python 3

print a, b, c

print(a, b, c)

print "%03d" % 7

print("{:03d}".format(7))

print x,

print(x, end=" ")

print >>sys.stderr, x

print(x, file=sys.stderr)

Python3-compatible code (last edited 2020-09-12 07:11:42 by chapoton)