Python has been recognised as one of the most popular languages on the planet, and is used in a lot of domains be it web and internet development, scientific and numeric computing, education, software development or business applications.

Python was released in the late 1980s followed by Python 2 in 2000 and python 3 in 2008.

Over time, numerous websites and web applications have been using python version 2 due to its wider acceptance in the tech community.

However, python is stopping the support for Version 2 from 31 December 2019

As the technologies are upgrading every day, the programming language Python also got a major upgrade i.e. from version 2.7 to 3.7 and this new version has much more features. Python 2.7.x and Python 3.7x support the libraries that we normally use. Therefore, it is worthwhile to have a look at the major differences between these two most popular versions of Python.

1. The print functions: –

Python 2’s print statement has been replaced by the print ( ) function, meaning that we have to wrap the object that we want to print in parentheses.

Python 2 doesn’t have a problem with additional parentheses, but in contrast, Python 3 would raise a Syntax Error if we called the print function the Python 2-way without the parentheses.

2. Integer division: –

This change is particularly dangerous if you are porting code, or if you are executing Python 3 code in Python 2, since the change in integer-division behaviour can often go unnoticed (it doesn’t raise a Syntax Error).

3. Unicode

Python 2 has ASCII str () types, separate Unicode () , but no byte type.

Now, in Python 3, we finally have Unicode (utf-8) strings, and 2-byte classes: byte and byte arrays

4. xrange

The usage of xrange is very popular in Python 2.7 for creating an iterable object, e.g., in a for-loop or list/set-dictionary-comprehension.

But here the xrange-iterable is not exhaustible — meaning, you could iterate over it infinitely.

The advantage of the regular range() is that xrange() is generally faster if you have to iterate over it only once (e.g., in a for-loop).

In Python 3, the range() was implemented like the xrange() function so that a dedicated xrange () function does not exist anymore (x range () raises a Name Error in Python 3).

5. The next() function and .next() method

Since next() (.next ()) is such a commonly used function (method), this is another syntax change (or rather change in implementation) that is worth mentioning: where we can use both the function and method syntax in Python 2.7., the next() function is all that remains in Python 3 (calling the .next() method raises an attribute Error ).

6. Banker’s Rounding

Python 3 adopted the now standard way of rounding decimals when it results in a tie (.5) at the last significant digits. Now, in Python 3, decimals are rounded to the nearest even number. Although it’s an inconvenience for code portability, it’s supposedly a better way of rounding compared to rounding up as it avoids the bias towards large numbers.

Frameworks and languages do come up with new and better versions every now and then. However, there’s still an ongoing debate in the developer community as to which version is best suited in a wider perspective. Let us know your choice in the comments below



Published On: August 22nd, 2019 / Categories: Technology /

Subscribe To Receive The Latest News

    Add notice about your Privacy Policy here.