During its development, Python branched in two versions, named 2.X and 3.X. Version 3.X is a cleaner release of Python's modules that intend to solve some design flaws [1]. Some of the improvements could not be done without loosing back compatibility with older versions. That said, version 2.X received a end-of-life date, and it was in the beginning of 2020. Therefore, if you starting to learn Python, go for version 3.X, unless your job is to maintain a system written for Python 2.X or it needs libraries not yet supported by 3.X.
The most notable differences between versions in the programmer's point of view are [2]:
- The print function now needs parenthesis, instead of being optional;
- Strings are stored in Unicode format, instead of ASCII;
- Division of integers can return a Float instead of rounding it to a integer.
One way to prevent runtime errors for the print function, is to use the "future package" in the first line of your Python file [3]:
from __future__ import print_function
Although the package is still on beta test [1], for the most common usage of print, it will work properly.
For the division of integers, a way to keep compatibility is to explicitly convert the result to int or float type, the one your code needs.
[1] Python wiki
No comments:
Post a Comment