Game Development Reference
In-Depth Information
Most of the programs in this topic make use of the newer version 3 of Python. The
Pygame games make use of Python 2 because the Pygame library is not yet compatible
with Python 3. Python 3 corrects many of the faults with version 2 of the langugae,
however, these changes can also make it impossible to run Python 3 programs with the
Python 2 interpreter, and vice versa.
There are only a few changes between the two versions, and this appendix will go
through the ones relevant to this topic. Learning both Python 2 and 3 is fairly simple. All of
the modules imported by the programs in this topic (except for the pygame module) are part
of the standard library and work with both Python 2 and Python 3.
In short, use Python 3 unless you need to use a library that is not yet compatible with
version 3. Learning both Python 2 and 3 is easy because there are only a few changes
between them.
The print() Function and the print statement
In Python 3, print() is a function just like input() or len() . The function version
requires parentheses just like any other function call (although you can add parentheses to
the print statement optionally).
The print statement in Python 2 will always print a newline character at the end of the
string. To make it print a space instead, put a comma at the end of the print statement:
>>> # Python 2
Search WWH ::




Custom Search