Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

Difference Between Python 2.x and Python 3.x

Both of these are iterations of Python, but there is a significant difference between Python 2.x and Python 3.x. In this article, we will discuss the same in a tabular form. Read ahead to know more.

Difference Between Python 2.x and Python 3.x

Here is a list of the differences present between Python 2.x and Python 3.x.

Parameters Python 2.x Python 3.x
Print Function In this case, it treats the “print” as a statement. In this case, it treats the “print” explicitly as a function. It means that a user needs to pass the concerned items inside the print to its function parentheses using a standard way. A syntax error will arise otherwise.
Integer Division It treats all the numbers typed without a digit after decimal points in the form of integers. As a result, we can get some very unexpected results during the time of division. Python 3.x does not do so in any way.
Unicode Strings It, by default, stores all the strings in the form of Unicode. The Unicodes are comparatively much more versatile than the ASCII strings (Python 2 default). It is because these can store all the letters from the foreign languages, emojis, and also the standard Roman letters along with the numerals. It also provides support for Unicode.
Raising Exception Python 2 can easily use the below syntax for raising an exception:

raise IOError, “your error message”

This syntax works only for Python 2.

Python 3 has fixed this kind of issue. It means that one can use the same name for the variable as something that they already used in naming the control variable in their “for loop”. There will be no chances of it leaking out and then messing with the values of the rest of the variables available in a code.
Name of Variables In this case, giving the same name to a global variable and a variable that gets iterated over in a “for loop” may lead to an alteration of the global value. It is something that we don’t generally want. Python 3 has fixed this kind of issue. It means that one can use the same name for the variable as something that they already used in naming the control variable in their “for loop”. There will be no chances of it leaking out and then messing with the values of the rest of the variables available in a code.

Keep learning and stay tuned to BYJU’S to get the latest updates on GATE Exam along with GATE Eligibility CriteriaGATE 2024GATE Admit CardGATE Application FormGATE SyllabusGATE CutoffGATE Previous Year Question Paper, and more.

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*