Python 3: Difference between revisions
No edit summary |
|||
(One intermediate revision by the same user not shown) | |||
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. | ||
Line 26: | Line 24: | ||
works like a charm. | works like a charm. | ||
Other than this, the quotient of two integers will now be a floating point number, so we | Other than this, the quotient of two integers will now be a floating point number, so we will not have the same integer division headaches. The rest is mostly technical, but | ||
if you care about the nitty-gritty details, look at the [http://docs.python.org/py3k/whatsnew/3.0.html what's new in Python 3.0 page]. | if you care about the nitty-gritty details, look at the [http://docs.python.org/py3k/whatsnew/3.0.html what's new in Python 3.0 page]. |
Latest revision as of 18:19, 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 will not have the same 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.