What’s in which Python 2.x?

Friday 30 September 2011This is more than 13 years old. Be careful.

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.

Update: I’ve now collected all the “What’s in which Python”s onto a single page: What’s in which Python.

BTW: there’s also What’s in which Python 3.0–3.3? and What’s in which Python 3.4–3.6?.

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
  • argparse
  • .format can use bare {} placeholders

Full list of 2.7 changes.

Comments

[gravatar]
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]
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]
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]
@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]
@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]
@Alex, a couple of suggestions: add a key/legend/tooltip and contact info. Nice site though :)

@Ned, why stick with Python 2.4?
[gravatar]
@Christian: it isn't my choice. The students work in an environment limited to 2.4, I don't know why.
[gravatar]
@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]
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]
Boolean datetype should be Boolean datatype.
[gravatar]
@limodou, thanks, I fixed it.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.