Main Content

Learning to program in Python 2 ... and / or in Python 3

Archive - Originally posted on "The Horse's Mouth" - 2010-05-24 23:50:31 - Graham Ellis

Yesterday - "Learning to Program in Python" - and I'm now teaching the day so that it's both Python 2 and Python 3 compatible. But it's really an intro day, and we'll vary how we go for the following 3 days of the course, majoring in an appropriate direction for our group - that's a luxury we have when our group sizes are typically 3 to 5 delegates on a public (open) Python course.

The big changes in Python 3 are that print has become a function (so needs brackets), that arithmetic has "gone floating", and that raw_input has become input. There's quite a few other things, but at the simple example level it's possible to write code that performs identically in both, as well as code that illustrates the differences. And we did both yesterday.

Here are the new example:

Hello world - fundamentals of Python, comparison to Java [link]

How integer arithmetic has become float arithmetic in Python 3 [link]

Calculation and printing - comparing Python 2 and Python 3 [link]

Input and raw_input - and how to write code that works in Python 2 and Python 3 [link]

If, elif and else ... and nesting of blocks [link]

A first example of a loop for newcomers to programming [link]

Count the number of records (and good hits) in a server log: [link]

Analysis of the records in a server log, by server response status: [link]