Why would we use Python 2 or 3?


#1

Question

Is there a reason to use Python 2 over Python 3, or vice versa?

Answer

In the software industry, some things take years to become the standard. Although Python 3 was released back in 2008, everyone’s code was already in production in Python 2. Given the amount of work it takes to update systems to a different version of a language, and the amount of testing it requires to ensure that a new language update offers more pros than cons is staggering.

Today, Python 3 is widespread, and the differences between 2 and 3 are very easy to catch up on. Learning Python 3 will be a matter of learning a handful of differences in syntax and functionality - the fundamentals are all the same.

If you’re curious, here’s Python’s very own documentation on the differences and what’s new in version 3!


FAQ: Learn Python - Python Syntax - Print Statements
#2

Consider also, proposed 2.7 end of life (EOL)


#3

It borders on irresponsible to suggest anyone start any project (or even support one) that uses Python 2 at this point. In 2020 all support to be discontinued (after already being prolonged in 2014, when it was originally supposed to end). At this point all the major libraries (TensorFlow, etc.) are implemented in Python 3.

Python 2 can be downright dangerous to teach to beginners because of integer division (not to mention lack of unicode string support). It is not just print() and input() that have changed.


#4

If is dangerous, I am wondering why Codeacademy has Python 2 for beginners. I wish everyone that decide to teach would have a common decision. I am new to Python and I bought a book called Hello World, Computer Programming for kids and other beginners, 2nd edition and unfortunately the author decided to go for Python 2.


#5

Because at the time it was much better supported with more modules and libraries. It is still the basis of the language and it is never harmful to know the earlier iterations of a language, even while they are going out of vogue and riding into the sunset.

Beginners are not writing production code, but are learning syntax, keyword usage, program constructs, data structures, variables, etc. It is not dangerous at all if one is learning and applying what they learn. Adapting to the current version of the language is a simple matter if they have taken seriously what they have learned and followed up with lots of reading and practice.


#6

Thank you, that is what I thought. It is not dangerous.


#7

From a standpoint of bullet proof code in a production setting facing the web, it stands to good reason that the most recent version is ported to the site. In-house code should meet the latest standards at all times.

For our purposes, though, we need not concern ourselves at this point with the issues that may come with version 2 that are addressed in version 3. If one is supremely interested, then there is ample reading material available online. Look for papers written by professionals as opposed to just opinion blogs or forums (that they may be one in the same notwithstanding).


#9