Python 3: Difference between revisions
Line 1: | Line 1: | ||
Python has undergone a non-backward-compatible update with Python 3. | Python has undergone a non-backward-compatible update with Python 3. | ||
Revision as of 18:08, 19 October 2011
Python has undergone a non-backward-compatible update with Python 3.
CASA still uses Python 2.x, and will for the foreseeable future. This may change someday, or you may want to use Python 3 somewhere else.
The good news is that Python 2.7 is forward compatible in some respects, so we should use the new syntax whenever possible. The place this is most obvious is with print.
print has moved from a statement to a function. Python 2.x is happy with either syntax, but as of 3.0 it only recognizes it as a function. For this reason, we recommend using it as a function right from the start. In Python 2.7 both of these work:
print 'Hello World'
print('Hello World')
However, in Python 3.x
print 'Hello World'
gives an error message, while
print('Hello World')
works like a charm.
Other than this, the quotient of two integers will now be a floating point number, so we do not have integer division headaches. The rest is mostly technical, but if you care about the nitty-gritty details, look at the what's new in Python 3.0 page.