Try it here
Python 2.x and Python 3.x

The difference between Python 2 and Python 3


Why should you use Python 3?

  • Python 3 supports modern techniques like AI, machine learning, and data science.
  • Python 3 is supported by a large Python developer's community. Getting support is easy.
  • Its easier to learn Python language compared to earlier versions.
  • Offers Powerful toolkit and libraries.
  • Mixable with other languages.

Key differences between Python 2 and 3

Functionality Python 3 Python 2
Release Date

2008 2000
Function print

print is a function in Python 3.
print("hello World")
print is a class in Python 2.
print "hello World"
Number 2**31 or greaterStored in int. Stored in long.
Operator <> Operator <> has been removedOperator <> can be used.
Division of Integers Whenever two integers are divided, you get a float value When two integers are divided, you always provide integer value.
Function returnsMost of the function returns iterable objects and it's more memory optimizedMost of the function returns the built-in object .
Character written in a fileNumber of characters written to file is returned Number of characters written to file is not returned
User input function raw_input was replaced with input in Python 3In Python 2, you have a built-in function raw_input() to take input from user

In Python 3, default storing of strings is Unicode. To store Unicode string value, you require to define them with "u".

The syntax is simpler and easily understandable. The syntax of Python 2 was comparatively difficult to understand.
Rules of ordering Comparisons In this version, Rules of ordering comparisons have been simplified. Rules of ordering comparison are very complex.

The new Range() function introduced to perform iterations. In Python 2, the xrange() is used for iterations.

It should be enclosed in parenthesis. It should be enclosed in notations.
Leak of variables

The value of variables never changes. The value of the global variable will change while using it inside for-loop.
Backward compatibility Not difficult to port python 2 to python 3 but it is never reliable. Python version 3 is not backwardly compatible with Python 2.

Many recent developers are creating libraries which you can only use with Python 3. Many older libraries created for Python 2 is not forward-compatible.

Writer profile pic

Aditya on Apr 16, 2020 at 02:04 am

This article is contributed by Aditya. If you like and would like to contribute, you can write your article here or mail your article to . See your article appearing on the main page and help others to learn.

Post Comment

Comments( 0)


Forgot Password

Please enter your email address below and we will send you information to change your password.