1. How the print function differs in Python 3 and 2 version?
Most notable and most widely known change in Python 3 is how the print function is used. Use of parenthesis () with print function is now mandatory. It was optional in Python 2.
4.
Most notable and most widely known change in Python 3 is how the print function is used. Use of parenthesis () with print function is now mandatory. It was optional in Python 2.
- print "Hello World" #is acceptable in Python 2
- print ("Hello World") # in Python 3, print must be followed by ()
- Python 2 has two versions of input functions, input() and raw_input(). The input() function treats the received data as string if it is included in quotes '' or "", otherwise the data is treated as number.
- In Python 3, raw_input() function is deprecated. Further, the received data is always treated as string.
|
Basis of comparison
|
Python
3
|
Python
2
|
|
Release Date
|
2008
|
2000
|
|
Function print
|
print ("hello")
|
print "hello"
|
|
Division of Integers
|
Whenever two
integers are divided, you get a float value
|
When two
integers are divided, you always provide integer value.
|
|
Unicode
|
In Python 3,
default storing of strings is Unicode.
|
To store Unicode
string value, you require to define them with "u".
|
|
Syntax
|
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.
|
|
Iteration
|
The new Range()
function introduced to perform iterations.
|
In Python 2, the
xrange() is used for iterations.
|
|
Exceptions
|
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.
|
|
Library
|
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.
|



