Python 3

From CASA Guides
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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.