Python 3

From CASA Guides
Revision as of 18:04, 19 October 2011 by Jkeohane (talk | contribs) (Created page with "== Python 3 == Python has undergone a non-backward-compatible update with Python 3. This is obviously a pain for existing Python programmers, but should be good for future Pyth...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Python 3

Python has undergone a non-backward-compatible update with Python 3. This is obviously a pain for existing Python programmers, but should be good for future Python programmers because it should be better.

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.

.