Python 3 is an improved version of the Python programming language over Python 2. There are numerous noticeable differences or improvements in the Python 3 versions. Some of them are that the syntax in Python 3 is simpler than in Python 2.
Exception arguments in Python 3 are represented by using parenthesis, which was not present in previous versions; print in Python 3 is a function, whereas print in Python 2 is a statement. When two integers were divided in Python 2, the resulting value was also shown as an integer, but Python 3 allows float value results as well, and the range() function is new in Python 3, which was not present in previous versions.
Python3 vs Python2
Python-3 | Python-2 |
A print is a type of function. | In python2, A print is a type of statement. |
Strings are stored as Unicode by default (UTF-8). | Labeled with “u” if stored as Unicode. |
If two integers are divided, a float value is returned if necessary. | When dividing two integers, always return an integer value. |
Syntax becomes more simple and understandable. | Compared to python3, the syntax here is a bit difficult. |
Variable values in Python 3 never change. | When global variables are used within a for-loop in Python 2, their values change. |
Python 3 was introduced in the year 2008. | Python 2 was introduced in the year 2000. |
Exceptions in Python 3 are enclosed in parentheses. | Exceptions in Python 2 are denoted by notations. |
Ordering comparison rules have been simplified. | It is more difficult to understand than Python 3. |
To perform iterations, Python 3 introduced the new Range() function. | Iterations are handled by the xrange() function in Python 2. |
Many libraries are written in Python 3 to be used only with Python 3. | Many Python 2 libraries are not fully compatible. |
Python 3 does not support backward compatibility with Python 2. | Python 2 code can be converted to Python 3 with considerable effort. |
Python 3 is used in a variety of fields such as software engineering, data science, and so on. | Python 2 was primarily used to train as a DevOps Engineer. It will be phased out by 2020. |
Comparing the Print statements
Python2: print “hello this is Python-Programs”
Python3: print(“hello this is Python-Programs”)
Comparison of the input statements
Python2:
For strings : raw_input()
For Integers : input()
Python3: input() – we use input for all kinds of input.
Print statement variables
Python2:
gvn_str = “welcome to Python-Programs”
print (“Given string = % ” % gvn_str )
Python3:
gvn_str = “welcome to Python-Programs”
print (“Given string = {0} “) .format(gvn_str ))
Comparing Error Handling: In Python3, the programmer must include an extra keyword in the except block.
Python2:
try:
//block code
except <ERROR>,err:
//block code
Python3:
try:
// block code
except <ERROR> as err:
// block code
When it comes to deciding whether to use Python 2 or Python 3, we can safely say that Python 3 is the clear winner. Also, if you are a new programmer, I would recommend Python3.