logo

Key Difference between Python 2.7.x and 3.x

   

Added on  2022-11-28

2 Pages884 Words206 Views
Key Difference between Python 2.7.x and 3.x
Abstract— This paper highlights the difference between two
python versions 2.7.x and 3.x and helps to understand the
pitfalls and avoid those pitfalls while working on any of the
version of python
I. SUMMARY
Most of the people are confused while selecting the
version of python for their project. As both the version of
python has support for large number of the libraries. Python
2.7.x and Python 3.x both are correct to be used and there
is nothing like to get confused between these two versions.
Any version can be used but the focus must be to understand
what are the major differences between the versions which
will help to avoid the pitfalls while working on either of the
version.
There is a module available ”future” which will help to
make the code compatible if written in 2.7.x and needs to
be supported on Python 3.x version. This module has all
the keywords which are incompatible with python 3.x and
through this module all these unsupported can be imported
and used with python 3.x.
The major difference between both the versions are: 1)
print function: In python 2.7.x print is the statement while
in python 3.x it has been made as function.Hence with 3.x
version print requires parenthesis and if no parenthesis added
then it shows exception but in 2.7.x version parenthesis
are not needed if added then it also works fine and treat
as tuple. 2) Integer division behaviour: In python 2.7.x if
two integers are divided then result will be integer and if
one integer is divided with float then result is float but in
python 3.x the division of two integer is float. This behaviour
remains unnoticed as this does not raise any exceptions. 3)
Unicode : Python 2.7.x version supports only str (string) and
Unicode but python 3.x version supports byte and byte array
as well. 4) xrange and range: In python 2.7.x it has both these
functions but in python 3.x range is implemented as xrange
and does not have any function as xrange. 5) Exception
handling: In 3.x version the exception is defined with the
help of ”as” keyword. 6) next method and function: In 2.7.x
both can be used but in 3.x only next function is supported.
7) input function: In python 3.x it treats everything as string
and raw input of 2.7.x is not supported.
II. CRITIQUE
Overall, this was a fairly well written notebook. The
issues which are noticed is that the use of language is not
simple and it takes time to understand the written points.
The examples which are used for some parts makes the user
confuse about the functionality such as for next function
and next method, for loop variables and for user inputs.
The explanation and description were followed properly till
the third difference later in the notebook the explanation
is reduced and it is hardly explanation the difference. The
comments are not present in the code which will give insight
about the functionality. The handing Comparing unorderable
types is not the major difference and it seems not relevant
to the context. If we overall look into the notebook then the
critics is positive.
III. SUGGESTED IMPROVEMENTS
Following are the suggestions for improvement:
1) Separate notebook in two major sections first section
will have those which are no longer present in other
version and second section section will have those
which are changed in the new version.
2) Use of simple language helps the beginner to under-
stand the terms and can also quickly learn things.
3) Put proper separation between the sections as it was
difficult to understand from where the section was
started and where it ends.
4) Use color and text formats must be use to highlight
the important terms and key values.
IV. CONCLUSION
The notebook for difference between the python versions
provides the details about the major difference among the
two versions. Also this notebook gives the understanding that
user can use any version of the python as both are correct and
support all the libraries but needs to keep in mind the pitfalls
among the version which is being used.By referring to this
notebook the things which are learnt are : for compatibility
make a habit to use ”future” module which will makes the
code supportable for python 3.x if developed in 2.7.x. It also
highlights the differences which can result in errors which
needs to be avoided such as ”print”, ”exception handling”,
”xrange” and ”next” method.
Hence for the successful coding in python and making the
code independent then the above points needs to be kept in
the mind and must be focused to be avoided.
.
APPENDIX
Fig. 1. Features in the releases
Key Difference between Python 2.7.x and 3.x_1

End of preview

Want to access all the pages? Upload your documents or become a member.