Programming languages come in all forms. Some happen to be a bit more complicated and others tend to be more beginner-friendly. They also come in numerous versions and that’s where things tend to get real finicky. You see, two versions of a programming language can be largely similar but will have some minor changes here and there that can wreak havoc on test and production environments alike.
One such example is Python 2 and Python 3. While both are quite similar and if you know Python 2 you’ll immediately pick Python 3 up, there are subtle differences and there that can catch you napping.
In this article, we’re going to take a look at how the two versions are different from each other and which one should you pick?
Also read: What’s the difference between C and C++?
So what’s the difference?
In layman terms, Python 3 is the future of Python. The language was initially released back in 2000 with Python 3 rolling out in 2008. Yes, Python 3 came out 12 years ago.
At first glance, you won’t find a lot of differences and that’s because there aren’t any. However, there’s a lot going on under the hood.
Since it’s quite hard to categorise differences together, we’re just focussing on the major differences between the two coding languages
|Python 3||Python 2|
|Easier to understand syntax||Comparatively difficult syntax|
|Exceptions must be enclosed in parenthesis||Exceptions must be enclosed in notations|
|range() function for iterations.||xrange() function for iterations|
|Stores strings in Unicode by default||Need to save in Unicode explicitly|
|Rules of ordering comparisons are simple||Rules of ordering comparisons are comparatively complex|
|Variables don’t change values unless specified||Global variable changes value when used in for loop|
|Print statement is print (“hello”)||Print statement is: print “hello”|
There are a lot of other differences under the hood as well that give Python 3 the edge over the former version.
Also read: Top 7 coding games
So which one should you use?
In 2020, unless you’re working with a piece of code that exclusively requires you to work with Python 2, there’s no reason to even touch the version. It’s deprecated and support for it will be dropped soon.
Python 3 is much more robust, easy to use and is the future of Python going forward.