What's in which Python?

Friday 30 September 2011

I'm teaching a class next week, and in their work environment, the students are limited to using Python 2.4. I wanted to be clear about what features of Python they'd have available, and which they wouldn't. The "What's New in Python" docs are very comprehensive, but spread out across many pages and full of distracting details.

So I made this list of the high points, what's in each version of Python 2.x. Items with a star were introduced with a __future__ import.

BTW: there's also a list for the 3.x series: What's in which Python 3?

2.1: April 17th, 2001

  • Nested scopes *
  • "from __future__"
  • Rich comparisons
  • Weak references

Full list of 2.1 changes.

2.2: December 21st, 2001

  • New-style classes
  • Iterators
  • Generators *
  • // integer division
  • Dividing ints can produce floats *

Full list of 2.2 changes.

2.3: July 29th, 2003

  • Set datatype module
  • Boolean datatype
  • Importing from zip files
  • enumerate
  • The logging and csv packages
  • Extended list slicing

Full list of 2.3 changes.

2.4: November 30th, 2004

  • Native set datatype
  • Generator expressions
  • Function decorators
  • string.Template
  • reversed()
  • The subprocess and decimal modules

Full list of 2.4 changes.

2.5: September 19th, 2006

  • The "with" statement *
  • Conditional expressions
  • The functools module
  • Unified try/except/finally
  • Value passed into generators
  • defaultdict
  • any(), all(), min(key=) and max(key=)

Full list of 2.5 changes.

2.6: October 1st, 2008

  • The multiprocessing package
  • str.format()
  • 3.0 compatibility: print function *, byte literals, io library
  • "except" with "as" keyword
  • Abstract base classes
  • Class decorators
  • The fractions module

Full list of 2.6 changes.

2.7: July 3rd, 2010

  • Set literals syntax
  • Dictionary and set comprehensions
  • OrderedDict and Counter classes

Full list of 2.7 changes.

tagged: » 12 reactions

Comments

[gravatar]
Eric Snow 10:21 PM on 30 Sep 2011

Awesome! It's fascinating to research this sort of stuff and see the progression of the language. I am working on something similar for just import-related stuff (though with more detail, delved from the depths of the repo).

[gravatar]
Malcolm Tredinnick 10:44 PM on 30 Sep 2011

Nice idea, Ned. Just last week I was bitten by something not in 2.5 in code I wanted to be portable back that far and I thought I'd read the "what's new in 2.x" docs pretty careful (not to mention having lived through all these releases as a professional developer). Yet my oversight item is in your list. Can see myself checking back with this list now and again for sanity.

Very nice work.

[gravatar]
joaquin abian 2:01 AM on 1 Oct 2011

Thanks for the summary. Great.
However, there is more python than python 2.x . Why did you choose to check only 2.x changes?. If they are young students, in the next future, they are going to be dealing with the 3 series rather than with python 2.

[gravatar]
Alex Willmer 4:33 AM on 1 Oct 2011

I have just the thing for you, http://comparethepython.com lists builtins, types, keywords, exceptions, modules, command line switches, environment variables and features by version from 2.2 to 3.2.

The site is new, you may find the characters I chose don't render on Windows. However the code is at https://github.com/moreati/pythoncompare and the source data is at http://docs.google.com/spreadsheet/ccc?key=0At5kubLl6ri7dHU2OEJFWkJ1SE16NUNvaGg2UFBxMUE&hl=en_US

[gravatar]
Ned Batchelder 8:45 AM on 1 Oct 2011

@joaquin: I stuck to 2.x for a few reasons: First, the course I'm teaching is 2.x, sp my immediate need was to know what features in the course they wouldn't be able to make use of. If the course mentions a 3.x addition, it's clearly labelled as such. Similarly, the entire Python community is still focused on the 2/3 split, so new 3.x features are generally clearly marked. But when people recommend the "with" statement, they rarely mention that it appeared in 2.5, because there's a general assumption that 2.x people are on a recent 2.x.

Maybe in the future I'll make add in the 3.x stuff.

[gravatar]
Ned Batchelder 8:47 AM on 1 Oct 2011

@Alex, comparethepython is very nice. You are right about the characters not appearing in my Windows Firefox browser. Perhaps an image sprite instead? Yours is another good source for detailed information about each release, which complements my 10,000-foot view nicely. Glad to see all the different slicing of the information.

[gravatar]
Christian Alis 10:36 AM on 1 Oct 2011

@Alex, a couple of suggestions: add a key/legend/tooltip and contact info. Nice site though :)

@Ned, why stick with Python 2.4?

[gravatar]
Ned Batchelder 12:09 PM on 1 Oct 2011

@Christian: it isn't my choice. The students work in an environment limited to 2.4, I don't know why.

[gravatar]
Ned Batchelder 1:14 PM on 1 Oct 2011

@Christian, I think I still wasn't clear. What I mean is, in their day jobs, outside of class, their work environment is limited to 2.4. The students are all with the same employer.

[gravatar]
Greg Hewgill 2:57 PM on 1 Oct 2011

You may be interested in https://github.com/ghewgill/pyqver which attempts to identify the minimum version of Python required to run a given script. It uses the `compiler` module to parse the source and then inspects the resulting syntax tree. There is a version of the script for Python 2 and one for Python 3.

[gravatar]
limodou 12:33 AM on 18 Oct 2011

Boolean datetype should be Boolean datatype.

[gravatar]
Ned Batchelder 5:52 AM on 18 Oct 2011

@limodou, thanks, I fixed it.

Add a comment:

name
email
Ignore this:
not displayed and no spam.
Leave this empty:
www
not searched.
 
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.