Python 2 vs Python 3

In most programming languages, a newer version supports previous one’s features and syntax so it is easier for developers to switch to newer version. However, it is not the case for Python. Python 2 and Python 3 are pretty much different from each other.

Learning which Python version was a bit of a debate in the coding community. I’m not sure about old Python users. They need to maintain old projects which were coded in Python 2. But new learners should choose Python 3.

List of differences between Python 2 and Python 3

Python 2Python 3
Strings are stored as ASCII by defaultStrings are stored as Unicode by default
print is a statement
Example: print “Test”
print is a function
Example : print(“Test”)
Many libraries made for Python 2 don’t support Python 3. Python 2 is legacy.New libraries made for Python 3 don’t support Python 2. Python 3 is the future.
xrange() is a sequence object that evaluates lazilyThis function is replaced by normal range()
You have to use integer in math, it rounds result to nearest integer.
Example: 7/2 = 3
This version has better integer support.
xample: 7/2 = 3.5

Leave a Reply

Your email address will not be published. Required fields are marked *