
Python 2 Vs Python 3
Python 2 Vs Python 3
In recent days, the coding community had a great discussion and debate about Python versions, and which was the best option to use in the IT field and many other industries. There were few count voting for Python 2 whereas, some turning towards Python 3.
Users who are new to use Python may get confused about the different versions available in today’s market. Though Python 3 is the latest version, still there are few developers using Python 2. You can see advantages in both the versions and utilize those based on the requirement. Now let us see the details on Python2 Vs Python 3.
Difference Between Python 2 Vs Python 3
S. No | Python 2 | Python 3 |
Initial Version and Released Year |
Python 2.0 – Released in the year 2000 |
Python 3.0 – Released in the year 2008 |
Latest Version and Released Year |
Python 2.7 – Released in the year 2010 |
Python 3.6 – Released in the year 2016 |
Version in Development |
None |
Python 3.7 under development |
Stability |
Python 2 is steadier and more translucent version |
Python 3 is to manage the design defects in the earlier versions |
Complexities |
Python 2 syntax is complex |
Python 3 syntax is simple and easy to understand |
Working of Print Statement |
Python 2 Print syntax is treated as a statement. Example: print(“hello”) |
Python 3 Print syntax is plainly treated as a function. Example: print “hello” |
Integer Division |
In Python 2, dividing two (2) integers constantly return a nearest whole number |
In Python 3, dividing two (2) integers result in an integer value |
Example of Integer Division |
3.0/2.0 = 1 |
3.0/2.0= 1.5 |
Python Libraries |
A large number of old Libraries are existing for Python 2 in many OS which is not forward-compatible |
Libraries are being developed and they are made strict to use with Python 3 |
Unicode Support |
Strings are stored as ASCII by default in Python 2. Add a prefix with “u” to make Unicode string |
Text strings are Unicode by default in Python 3 |
String and Bytes |
String and Bytes are treated as same in Python 2 |
String and Bytes are not treated as same in Python 3 |
Handy Function |
Two (2) handy functions to create a range of integers in Python 2: range and xrange functions |
One (1) handy function to create a range of integers in Python 3: range function |
Example of Handling Exception |
except IOError, err: |
except IOError as err: |
Leak of for-loop variables |
For-loop variable leaks into the global namespace |
For-loop variable does not leak into the global namespace |
.next() method |
Both .next() method and next() functions are available in Python 2. This is to draw the following element of an iterator |
next() function is only available in Python 3 to draw the following element of an iterator |
input() method |
There are two (2) methods in Python 2 to take input: input() and raw_input() |
Python 3 has only one input taking method which is input(). raw_input() is not available in Python 3. In case to use raw_input() like Python 2, make use of eval () method |
Not equal operator |
For not equal operator in Python 2, use greater than and lesser than signs |
For not equal operator in Python 3, use general signs like exclamation marks and equal to |
Rules of Ordering Comparison |
Rules of ordering comparison in Python are extremely complex |
Rules of ordering comparisons in Python 3 have been made simpler |
Conclusion
A survey conducted in 2014 declared that two-thirds of developers are using Python 2 when compared to Python 3. In the year 2013, just 22 percent of people used the latest version. However, the transition from Python 2 to Python 3 is happening gradually. But the fact is you can use any version to write operative, beneficial, and competent code. If you are planning to move from Python 2 to Python 3, better check with the library support.