Python 2 vs Python 3

Anshuman
Nov 3, 2020

Similarities

1.Both versions belong to High-level programming language category.

2.Both are a multi paradigm Object-oriented programming and Procedure-oriented programming[Functional programming can also be observed .see map() ].

3.Both are interpreted.

4.Execution is slow comparing to compiler based languages.

5.Both versions are a free and open source[maintained by PSF].

6.Python shell provides an interactive mode for both Python 2 and 3.

7.Both are capable to interface with various databases such as MySQL ,Oracle etc.

8.Both have availability of number of packages.

Numpy’, ‘Scipy’ for Scientific computing, ‘Matplotlib’ for data visualization, ‘Django’, ‘Flask’ for building websites.

9.Both can implement Multithreading.

Differences

Python 2 will get minimum support in future ,Python 3 is the future.

1)Print Function

py 2

print “no parenthesis”

vs

py 3

print(“parenthesis required”)

got the difference?

2)Integer Division

py 2

5/3 will return 1

vs

py 3

5/3 will return 1.66666667

Input from the user

Raw_Input() ::In Python 2, raw_input() function is used to get input from the user. This function reads a string.

In Python 3, raw_input() function is not available.

Input () Function::In Python 2, input() function can be used to read as strings if they are inside quotes else read as numbers.In Python 3, input() function reads the input as a string.[So raw input() in py2 is equivalent to input() in py3]

If you are starting your python journey today,I would recommend python 3,as it is more intuitive(take integer division for example).The industry is switching to python 3,and you should go with the flow.

--

--

Anshuman
0 Followers

CS undergrad into physics🚩Linguistics Economics