r/Python • • May 30 '19

Dear python2 user

Post image
1.9k Upvotes

275 comments sorted by

View all comments

8

u/[deleted] May 30 '19

I was encouraged to learn 2.7 and stick with it over 3 about 3 years ago and aside from the print statements I can’t really figure out what’s different (I’m not a programmer; I use it for data analysis, image processing in astronomy, and playing around). What are some of the big differences between 2 and 3, in the language of non-CS people?

7

u/[deleted] May 30 '19

There are lots and lots of massive changes that occurred from 2 to 3. New libraries, new builtins, syntax changes, more consistent naming, etc. But in my opinion, the biggest change was from eager evaluation to lazy evaluation.

The easiest example is range. In python 2, range creates a list of integers before executing the next line. This potentially slows the runtime down immensely if the number is large enough. Python 3 changes that by only adding to the list when it reaches that point. This removes that upfront cost, and in general speeds up the program.

9

u/alcalde May 30 '19

New libraries, new builtins, syntax changes, more consistent naming, etc. But in my opinion, the biggest change was from eager evaluation to lazy evaluation.

Fascinatingly you completely left out the Unicode string change, which is usually cited as the major change. :-)

2

u/[deleted] May 31 '19

It was actually THE change that broke python 2 code (actually to be correct most python 2 code is broken, python 2 just didn't complain about it). Basically if you have python 2 code chances are that it will mess up unicode text.

The other incompatible changes were because of it. They thought that since compatibility was broken anyway, why not just use that as an opportunity to cleanup the language.