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.

1

u/regeya May 30 '19

Yeah, range() behaves more like xrange() now. Parens in print statements can be annoying after being used to not using them, but it helps with clarity imho.