Learning to program in Python 2 ... and / or in Python 3
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]
(written 2010-05-24, updated 2010-05-25)
Associated topics are indexed under
Y300 - Python 3 - What is new, what's changed and why [2871] Moving from Python 2.6 to Python 3 - (2010-07-14)
[2559] Moving the product forward - ours, and MySQL, Perl, PHP and Python too - (2010-01-01)
[2285] Great new diagrams for our notes ... Python releases - (2009-07-13)
[2277] Python classes / courses - what version do we train on? - (2009-07-10)
[1791] The road ahead - Python 3 - (2008-09-10)
[1788] Python 2 to Python 3 / Python 3000 / Py3k - (2008-09-07)
[753] Python 3000 - the next generation - (2006-06-09)
Y050 - Python - General [3935] Whether you have programmed before or not, we can teach you Python - (2012-11-25)
[3911] How well do you know Perl and / or Python? - (2012-11-04)
[3903] Python Programming class for delegates who have already self-taught the basics - (2012-10-25)
[3902] Shell - Grep - Sed - Awk - Perl - Python - which to use when? - (2012-10-22)
[3816] Want to escape the Olympics? Learn to program in the countryside! - (2012-07-23)
[3798] When you should use Object Orientation even in a short program - Python example - (2012-07-06)
[3519] Python - current versions and implementations (CPython, Jython, IronPython etc) - (2011-11-13)
[3489] Python courses and Private courses - gently updating our product to keep it ahead of the game - (2011-10-20)
[3463] Busy weekend of contrasts. - (2011-10-03)
[3076] Python through the Snow - (2010-12-01)
[2822] Python training courses for use with ESRI ArcMap software - (2010-06-23)
[2504] Learning to program in ... - (2009-11-15)
[2394] Two days of demonstration scripts in Python - (2009-09-05)
[2367] Learning to program - how to jump the first hurdles - (2009-08-20)
[2227] Learning PHP, Ruby, Lua and Python - upcoming courses - (2009-06-11)
[2020] Learning Python - many new example programs - (2009-01-31)
[2017] Python - a truly dynamic language - (2009-01-30)
[16] Python training - (2004-08-16)
Y102 - Python - Fundamentals [3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
[3886] Formatting output - why we need to, and first Python example - (2012-10-09)
[3551] Some terms used in programming (Biased towards Python) - (2011-12-12)
[3278] Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (2011-05-05)
[3181] Beware - a=a+b and a+=b are different - Python - (2011-02-23)
[3083] Python - fresh examples from recent courses - (2010-12-11)
[2442] Variable storage - Perl, Tcl and Python compared - (2009-10-08)
[2368] Python - fresh examples of all the fundamentals - (2009-08-20)
[1878] Pascals Triangle in Python and Java - (2008-11-10)
[1461] Python - input v raw input - (2007-12-06)
[1448] Question on division (Java) - Also Perl, PHP, Python ... - (2007-11-28)
[1430] Integer v float - Python - (2007-11-12)
[956] Python security - trouble with input - (2006-11-30)
[748] Getting rid of variables after you have finished with them - (2006-06-06)
[633] Copying a reference, or cloning - (2006-03-05)
[328] Making programs easy for any user to start - (2005-05-29)
Y103 - Python - Conditionals and Loops [3895] Flowchart to program - learning to program with Well House - (2012-10-14)
[3762] Learning to program - the if statement. Python. - (2012-06-12)
[3620] Finding the total, average, minimum and maximum in a program - (2012-02-22)
[3558] Python or Lua - which should I use / learn? - (2011-12-21)
[3439] Python for loops - applying a temporary second name to the same object - (2011-09-14)
[3397] Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18)
[3200] How a for loop works Java, Perl and other languages - (2011-03-12)
[2899] Groupsave tickets - 3 or 4 train tickets for the price of 2 - (2010-08-02)
[1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
[1661] Equality, sameness and identity - Python - (2008-05-31)
[1477] Decisions - small ones, or big ones? - (2007-12-18)
[1201] No switch in Python - (2007-05-23)
[909] Python is like a narrowboat - (2006-10-30)
[835] Python - when to use the in operator - (2006-08-16)
[788] New - Conditional expressions in Python 2.5 - (2006-07-01)
[668] Python - block insets help with documentation - (2006-04-04)
[657] The ternary operator in Python - (2006-03-25)
[353] Wimbledon Neck - (2005-06-20)
[299] What - no switch or case statement? - (2005-05-03)
57d7
Some other Articles
Tell the Melksham Chamber or you only have yourself to blameThe 500 pound question to get you startedFormatted Printing in PythonThe history and future of Melksham Chamber of CommerceLearning to program in Python 2 ... and / or in Python 3Blowing our own trumpetRegional Spatial Strategy and the next 20 years - Whence Wiltshire under the new government?Declarations of interest - knowing where you stand with peoplePHP - Object Oriented Design in useDynamically watching your web site via a PHP wrapper