Python 2 or 3
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Dec 3 05:04:07 EST 2011
On Sat, 03 Dec 2011 05:54:19 +0200, Antti J Ylikoski wrote:
> The O'Reilly book has some 1200 pages. I would not want to invest such
> an amount of work and time to an obsolete language (i. e. Python 2).
Python 2 is not an obsolete language. The differences between Python 2
and Python 3 are minor, more like different dialects of one language than
two languages. I learned Python 1.5 and watched the extended transition
between 1.5 -> 2.2, and in my opinion, the 2.5 -> 3.2 transition is not
that much more difficult.
An experienced programmer won't have any difficulty learning both, and
swapping between them. Newbies who have never programmed before often
have trouble with the differences between 2.x and 3.x, but if you are an
experienced programmer, you shouldn't have any trouble at all. The
biggest difference to the language is that strings are now Unicode
instead of byte strings; this has forced a lot of English speakers to
learn about Unicode and bytes instead of assuming that the universe is
ASCII. Apart from that, the differences are, in my opinion, trivial.
However, there are a lot of them:
http://docs.python.org/release/3.0.1/whatsnew/3.0.html
But the most important ones in my opinion are:
* unicode text, as mentioned above, and the consequences of this;
* some of the modules in the standard library have been renamed;
* various new modules have been added;
* some built-in functions and methods which used to return lists now
return lazy iterators or views;
* print is now a function instead of a statement;
* a small number of syntax changes, some of which are also supported by
Python 2.6 and 2.7;
* "classic classes" no longer exist, so there is now only one class
mechanism, not two.
If you can deal with the difference between these two lines without
getting confused:
print md5.md5("spam").hexdigest() # Python 2.x
print(hashlib.md5("spam").hexdigest()) # Python 3.x
you're half way there.
--
Steven
More information about the Python-list
mailing list