What are the differences between Python 2.x vs Python 3.x (2.7 vs 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9), When to use Python 2.x over Python 3.x and vice versa
What are the differences between Python 2.x vs Python 3.x (2.7 vs 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9)
The final 2.x version 2.7 released in the middle of 2010. Python 3.x latest version is 3.6.4 (at the time of writing this article). Python 3.3 released in 2012, 3.4 in 2014, 3.5 in 2015 and 3.6 in 2016.
The following are some of the key differences between Python 2.x and Python 3.x:
• strings are Unicode by default
• clean Unicode/bytes separation
• exception chaining
• function annotations
• syntax for keyword-only arguments
• extended tuple unpacking
• non-local variable declarations
When to use Python 2.x over Python 3.x and vice versa:
If it is new development environment without Python 2.x old code, then it is BEST to use Python 3.x because it PRESENT and FUTURE!
Most of the Linux distributions have Python 3.x already installed, and nearly all have it available for end-users. One exception is Red Hat Enterprise Linux through version 7: Python 3 does exist in the EPEL repository, but some users may not be allowed by company policy to install anything from such add-on locations.
If it is old environment with lot of Python 2.x code, then the decision becomes complex about using Python 3.x. On the long run, better to migrate to Python 3.x but for short-term needs stick with 2.x .
The following are the unique cases where you may end up using Python 2.x over Python 3.x:
• Externally controlled environments: You are not controlling the environment but you have the code to deploy, in this case you must use a specific version suggested by the environment control teams. They will not allow you to select from the available versions.
• Third-Party Package or Utility: If you are using a specific third-party package or utility that doesn't have a version that is compatible with Python 3 but compatible with Python 2, then use Python 2 to make the package work for your needs.