LuvLetter
2016-07-11 17:35:37 +08:00
Which Python Should I Use?
Version choice may be mandated by your organization, but if you ’ re new to Python and learning on your own, you may be wondering which version to install. The answer here depends on your goals. Here are a few suggestions on the choice.
When to choose 3.X: new features, evolution
If you are learning Python for the first time and don ’ t need to use any existing 2.X code, I encourage you to begin with Python 3.X. It cleans up some longstanding warts in the language and trims some dated cruft, while retaining all the original core ideas and adding some nice new tools. For example, 3.X ’ s seamless Unicode model and broader use of generators and functional techniques are seen by many users as assets. Many popular Python libraries and tools are already available for Python 3.X, or will be by the time you read these words, especially given the con- tinual improvements in the 3.X line. All new language evolution occurs in 3.X only, which adds features and keeps Python relevant, but also makes language definition a constantly moving target — a tradeoff inherent on the leading edge.
When to choose 2.X: existing code, stability
If you ’ ll be using a system based on Python 2.X, the 3.X line may not be an option for you today. However, you ’ ll find that this book addresses your concerns, too, and will help if you migrate to 3.X in the future. You ’ ll also find that you ’ re in large company. Every group I taught in 2012 was using 2.X only, and I still regularly see useful Python software in 2.X-only form. Moreover, unlike 3.X, 2.X is no longer being changed — which is either an asset or liability, depending on whom you ask. There ’ s nothing wrong with using and writing 2.X code, but you may wish to keep tabs on 3.X and its ongoing evolution as you do. Python ’ s future remains to be written, and is largely up to its users, including you.
When to choose both: version-neutral code
Probably the best news here is that Python ’ s fundamentals are the same in both its lines — 2.X and 3.X differ in ways that many users will find minor, and this book is designed to help you learn both. In fact, as long as you understand their differ- ences, it ’ s often straightforward to write version-neutral code that runs on both Pythons, as we regularly will in this book. See Appendix C for pointers on 2.X/3.X migration and tips on writing code for both Python lines and audiences.