What is the Difference Between Python2 and Python3 - Programmer's Academy

What is the Difference Between Python2 and Python3

Python is almost 30 years old programming language. As an experienced old language, it has made things easy for its user as it has a library for everything. It has minimized user’s effort and provides built in functions for literally everything. The big difference between python and other languages is how easy it is to read. Initially python 2 was used as mainstream python language but it has some loose ends/gaps and to fill these gaps python 3 was introduced. Python 2.7 is still used widely as many systems are already running on it. In this article we will learn about difference between python 2 and python 3.

Print Function

In python 2 the Print was considered as a statement, for example you can print “hello world” using syntax

Print “hello world”

But in Python3 the Print is made function that is used with the parentheses such as

Print (“hello world”)

Integer division

In python 3 integer division was improved. In python 2 the resultant value after division is integer but in python the resultant value becomes float by default, hence giving more precise results.  Let us check through an example.

Python 2:

Python 3:

Difference in error handling

The syntax for showing an error message after a certain event is different in both versions of python.

Exception message Python 2 syntax Python 3 syntax
Sorry sir you cannot divide by 0 raise IOError, “Sorry sir you cannot divide by 0” raise IOError(“Sorry sir you cannot divide by 0”)

Unicode

By default, python 3 sorts string as Unicode but in python 2 strings are stored as ASCII by default, to store Unicode string value we must mention “u” with string. Unicode is more flexible than ASCII, so it has wide options such as letters, characters, alphabets romans, symbols.

For-loop variable problem

In python 2 if the for-loop variable and global variable have a same name then during execution of program global variable value changes. This problem was solved in python 3.

Python 2:

Python 3:

Other Differences

Differences Python2 Python 3
Syntax Complex syntax not much user friendly and easy to understand Simple syntax, user friendly easy to understand
Backward compatibility Compatible with python 3 Not compatible with python 2
Libraries Older libraries Advanced libraries as it is being used currently as mainstream python
Legacy It is old version in future it will be soon vague Python 3 is future and is here to stay
Release Date 2000 2008

 

Help Me Please: If you found any error in the content or example please let us know by comment also write your suggestion or if any doubt in the concept please feel free to write us in the comment section.

Practice your Code online here

(Visited 131 times, 1 visits today)

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
You cannot copy content of this page
Scroll Up
0
Would love your thoughts, please comment.x
()
x

  • Name

  • Minimum length of 8 characters.