Is the Time Right to Learn Python 3?

Python 3 Installer

Python is an excellent and very popular programming language, considered one of the best-designed. It has a simple, clear syntax and runs very fast (faster if you compile it with CPython), but there is one slight problem facing anyone new to it: Which version should you learn?

There are two versions of PythonPython 2 and Python 3. Python 2.7 is the last of the 2.* series (currently up to 2.7.7) and has been the recommended version to learn for ages. Python 3 has been seen as not-quite-ready, though worth trying if you wanted. The current version is 3.4.1.

Click here to find Python developer jobs.

What’s the Problem With Python 3?

Python 3 was introduced in December 2008 to correct deficiencies perceived by its inventor, Guido Van Rossum. This included changing core strings to be fully Unicode-compatible, changing print to be a function, division with / and returning a list of ints from the range() function. Add to this exception-chaining, function annotations, extended tuple unpacking and non-local variable declarations. Python 3.4.1 added proper Enum support to eliminate the older “make a class look like an Enum” that was found in previous versions. The good news is that the new Enums have been backported to Python versions 2.4-2.7 and 3.1-3.3.

The problem remains, though, that there’s an awful lot of Python 2 code out in the world that needs to be converted to Python 3. As we saw in my earlier article on popular Python frameworks, not all Web frameworks are Python 3-compatible yet. Web2py isn’t. Likewise, the very popular py2exe, which compiles Python scripts to run under Windows as .exes, is restricted to Python 2.6 and 2.7 (though there are alternatives such as cx_Freeze). Generally, there are still more libraries compatible with Python 2 than Python 3, but I believe the tipping point will come very soon.

Arguably, the move to Unicode is probably the one big reason for the change. If you’ve never had to deal with Unicode, take a look at Pragmatic Unicode, a series of slides by Ned Batchelder that shows why the change was needed. The short version is that the world runs on Unicode and the Python 2 implementation can cause problems unless you are very careful. In a way it’s analogous to moving away from C strings to the much safer C++ strings. Ironically, it was the C heritage of Python 2 that led to many of its quirks in the first place. The world has changed somewhat since Guido invented Python in 1991.

If you’re learning Python from scratch, you should go with Python 3. Some interesting stats from Nick Coughlan’s Python Notes show almost 38,800 packages, of which 26,500 claim compatibility with any version of Python. Seventy percent of the top 200 downloaded packages offer Python 3 support and it’s hard to imagine that figure not increasing with time.

Related Articles

2 Responses to “Is the Time Right to Learn Python 3?”

  1. Unca Alby

    Once again another “upgrade” ignores backward compatibility.

    What is the matter with these people? What’s wrong with them? Have they nothing better to do but invent new ways of doing the same old thing? Do they have NO concept that TIME IS MONEY and, outside of a University environment, people just can not afford to expend the resources to “upgrade” the entire business every time they think up a new whiz-bang gimmick?

    I’m reminded of that apocryphal, but funny, reprimand from GM to Microsoft, where among other things, you have to buy a brand new automobile every time they paint the stripes on the road. And these days they paint the stripes about twice a month.

  2. You can get Unicode to work in Python 2 as well as get Python 3 to run Python 2 (as long as you have Python install as well) if you put these two lines at the top of your code.

    # -*- coding: utf-8 -*-

    I’m using both Zed A. Shaw’s ‘Learn Python The Hard Way’ and Codecademy’s Python tutorials to learn Python with. Both use Python 2. After finishing both of these, I plan to go through ‘Become a Professional Python Programmer’ on Udemy which should cover Python 3 and the new features it offers.