Appendix C. What's New in Python 3.1

Python is constantly changing in little ways. Python 3.1 has evolved from version 2.6, but it contains important changes. This appendix introduces you to the changes relevant to the topics covered in this book. This means that this is not an exhaustive treatment by any means but only a selection of topics touched on in the book — topics that you may want to know as someone new to Python.

You can find the official list of changes to Python 3.1 at If a newer version of Python is available by the time you read this, you can find the list of changes for that version on the Python website as well.

Print Is Now a Function

In the olden days of yore, print was a statement. With version 3.1, it has reached the major leagues and is now a bonafide function — specifically, print().

Certain APIs Return Views and Iterators

The following no longer return lists, but instead return views and iterators:

  • The dict methods — dict.keys(), dict.items(), and dict.values. You will also note that dict.iterkeys(), dict.iteritems(), and dict.itervalues() are no longer supported methods in Python.

  • Both map() and filter() return iterators instead of lists.

  • The range() method has replaced xrange() and is used in the same manner.

  • The zip() method is now used to return an iterator.


The long data type has been renamed to int (basically the only integral type is now int). It works in roughly the same manner as the long type did. Integers ...

Get Beginning Python®: Using Python 2.6 and Python 3.1 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.