Difference between Python 2.7 and Python 3
Python 3 vs Python 2 are getting used widely in an organization as per their requirements. Python 2. X is widely used as it is stable for a long time. Python 3. X is also getting into a notice of developers. Developers used to go with python 2 as from python 2 to python 3 transitioning is happening and some of the libraries are not available in Python 3 which is very helpful in python 2.
There is the following
difference between [ython 3 and python 2.
1. Print function — In python 3, a print function
has been used means arguments should be enclosed in parenthesis. for example
print(“this is python3”) instead in python 2, a print is treated as a statement
for example print” this is Python2”.
2. programming language effectiveness— In python
3, syntax changes are done to make the programming language more effective and
easy for the developers compared to Python 2.
3. New built-in functions— In Python 3, new
built-in functions are included, and some are removed and renamed as compared to
python2.
4. Compatibility— Python 3 has been developed in
such a way that Python 3 is incompatible with python 2.
5. GUI applications— Python 3 has been broadly
supported for developing a wide range of GUI(Graphic User Interface)
applications and many other packages are available in Python 3 as compared to
Python 2.
6. Value of integer— In python 3, the value of
integer division would be appropriate by default, for example, if we would like to
divide 5/2 it will give a result of 2.5. but in Python 2, we need to provide the data type as a float if the output will come in decimal otherwise only the
result will come in an integer. only. for example 5/2 it gives result 2.
7. Text and data— In python 3, text and data have
been used. Unicode(UTF-8) is a default encoding source for python 3 and str
represented as a length 1 string. but in Python 2, str is represented as the length
8-bit string.
8. Exceptions— The exception argument should be
enclosed in parenthesis in python 3 but in python 2 the exception argument can
be enclosed in notations. In python 3, for handling or catching an exception we
need to use a keyword. it is except Error as err(except some exception as a
variable) but in python 2, we need to use,’ for the same except Error, err(
except some exception, err).
9. Iterators and lists — Range() function
introduced for iterations in Python 3 and Xrang() is used for iterations in
python 2.
10. comparisons— the rules of ordering comparisons
have been simplified in python 3 but in python 2 the rules of order is more
complex.
11. syntax changes— In python 3, syntax becomes
simple and easily understandable but in python 2, it was quite difficult to
python 3.
12. Unicode— By default storing strings as Unicode
(UTF-8) in python 3, but in python 2 for storing as Unicode, need to label with
“u”.
13. Division of integers — as we know before, when
two integers are divided, in python 3 it will get a float value if required. but in
python2 when two integers are divided, always gives an integer value only.
14. Leak of variable— the value of variables
doesn’t leak in python 3 but the value of the global variable got changed while
using that in for-loop.
Comments
Post a Comment