Python 2 and 3 got many differences between them. In this article, we will go through some important differences between them. While comparing these two, it is pretty clear that python 3 is much better than 2. Python 2 is a legacy, whereas Python 3 is the future.
- Python 3 syntax is simpler and easily understandable whereas Python 2 syntax is comparatively difficult to understand.
- In Python 3, print is a function, whereas in Python 2 print is a statement.
- In Python 3, 5/2 is equal to 2.5 while in Python 2, 5/2 will give 2 as output.
- Python 3 default storing of strings is Unicode whereas Python 2 stores need to define Unicode string value with “u” and strings are stored as ASCII by default.
- In Python 3, the value of variables never changes whereas in Python 2 the value of the global variable will be changed while using it inside for-loop.
- Python 3 exceptions should be enclosed in parentheses while Python 2 exceptions should be enclosed in notations.
- Python 3 rules of ordering comparisons are simplified whereas Python 2 rules of ordering comparison are complex.
- Python 3 offers Range() function to perform iterations whereas, In Python 2, the xrange() is used for iterations.