Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
python2
python3

Python 2 vs. 3

Educative Answers Team

Python 3 was initially released in December 2008. It was designed to rectify some fundamental design flaws in the language that Python 2 introduced.

The guiding principle of Python 3 was: “reduce feature duplication by removing old ways of doing things”. Python 2 frequently supported many ways to perform the same tasks, an issue Python 3 was intended to tackle.

Although there’s some debate about “better,” it’s generally recommended that newcomers should focus on learning Python 3. This is because Python 2 is not going to be supported from 2020 onwards.

Python 3

String Encoding

Python 2

svg viewer
svg viewer

Python 3 stores strings as Unicode by default.

Division

Python 2 stores them as ASCII. Unicode is a superset of ASCII and hence, can encode more characters including foreign ones.

svg viewer
svg viewer

Division in Python 3 returns the expected output, even if it is in decimals.

Print

Python 2 division applies the floor function to the decimal output and returns an integer. So dividing 5 by 2 would return floor(2.5) = 2.

svg viewer
svg viewer

The syntax for the print statement is different in Python 2 and 3. Python 3 requires parentheses around what is to be printed.

Libraries

Python 2 does not require parentheses.

svg viewer
svg viewer

Many older libraries were built specifically for Python 2 and are not “forward compatible.”

Legacy

Python 2 is entrenched in the software landscape to the point that co-dependency between several softwares makes it almost impossible to make the shift.

Some newer libraries are built specifically for Python 3 and do not work with Python 2.

RELATED TAGS

python
python2
python3
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring