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 as below, or enter http://melksh.am/nnnn for individual articles
Y300 - Python 3 - What is new, what's changed and why [753] Python 3000 - the next generation - (2006-06-09)
[1788] Python 2 to Python 3 / Python 3000 / Py3k - (2008-09-07)
[1791] The road ahead - Python 3 - (2008-09-10)
[2277] Python classes / courses - what version do we train on? - (2009-07-10)
[2285] Great new diagrams for our notes ... Python releases - (2009-07-13)
[2559] Moving the product forward - ours, and MySQL, Perl, PHP and Python too - (2010-01-01)
[2871] Moving from Python 2.6 to Python 3 - (2010-07-14)
[4469] Sorting in Python 3 - and how it differs from Python 2 sorting - (2015-04-20)
[4470] Testing in Python 3 - unittest, doctest and __name__ == __main__ too. - (2015-04-21)
[4590] Progress on moving from Python 2 to Python 3 - training for both versions - (2015-12-01)
[4649] Object and Static methods - what is the difference; example in Python 3 - (2016-02-17)
[4650] Why populate object with values as you construct them? - (2016-02-18)
[4711] Convering from Python 2 to Python 3 - an update, and the 2to3 utility - (2016-10-30)
[4712] A reminder of the key issues to consider in moving from Python 2 to Python 3 - (2016-10-30)
Y103 - Python - Conditionals and Loops [299] What - no switch or case statement? - (2005-05-03)
[353] Wimbledon Neck - (2005-06-20)
[657] The ternary operator in Python - (2006-03-25)
[668] Python - block insets help with documentation - (2006-04-04)
[788] New - Conditional expressions in Python 2.5 - (2006-07-01)
[835] Python - when to use the in operator - (2006-08-16)
[909] Python is like a narrowboat - (2006-10-30)
[1201] No switch in Python - (2007-05-23)
[1477] Decisions - small ones, or big ones? - (2007-12-18)
[1661] Equality, sameness and identity - Python - (2008-05-31)
[1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
[2899] Groupsave tickets - 3 or 4 train tickets for the price of 2 - (2010-08-02)
[3083] Python - fresh examples from recent courses - (2010-12-11)
[3200] How a for loop works Java, Perl and other languages - (2011-03-12)
[3397] Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18)
[3439] Python for loops - applying a temporary second name to the same object - (2011-09-14)
[3558] Python or Lua - which should I use / learn? - (2011-12-21)
[3620] Finding the total, average, minimum and maximum in a program - (2012-02-22)
[3762] Learning to program - the if statement. Python. - (2012-06-12)
[3895] Flowchart to program - learning to program with Well House - (2012-10-14)
[4092] Identity in Python - (2013-05-17)
[4210] If elif elif elif - multiway selection in Python - (2013-11-16)
[4322] Learning to Program - the conditional statement (if) - (2014-11-21)
[4323] Learning to program - Loop statements such as while - (2014-11-22)
[4402] Finding sum, minimum, maximum and average in Python (and Ruby) - (2015-01-19)
[4541] Setting up and tearing down with the Python with keyword - (2015-10-16)
[4545] Method, Class, Module, Package - how to they relate in Python? - (2015-10-17)
[4713] Equality (in Python) - (2016-10-30)
[4723] Conditional operators in Python - (2016-11-05)
Y102 - Python - Fundamentals [328] Making programs easy for any user to start - (2005-05-29)
[633] Copying a reference, or cloning - (2006-03-05)
[748] Getting rid of variables after you have finished with them - (2006-06-06)
[956] Python security - trouble with input - (2006-11-30)
[1430] Integer v float - Python - (2007-11-12)
[1448] Question on division (Java) - Also Perl, PHP, Python ... - (2007-11-28)
[1461] Python - input v raw input - (2007-12-06)
[1878] Pascals Triangle in Python and Java - (2008-11-10)
[2368] Python - fresh examples of all the fundamentals - (2009-08-20)
[2442] Variable storage - Perl, Tcl and Python compared - (2009-10-08)
[3181] Beware - a=a+b and a+=b are different - Python - (2011-02-23)
[3278] Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (2011-05-05)
[3551] Some terms used in programming (Biased towards Python) - (2011-12-12)
[3886] Formatting output - why we need to, and first Python example - (2012-10-09)
[3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
[4324] Learning to program - variables and constants - (2014-11-22)
[4442] Mutable v Immuatble objects in Python, and the implication - (2015-02-24)
Y050 - Python - General [16] Python training - (2004-08-16)
[2017] Python - a truly dynamic language - (2009-01-30)
[2020] Learning Python - many new example programs - (2009-01-31)
[2227] Learning PHP, Ruby, Lua and Python - upcoming courses - (2009-06-11)
[2367] Learning to program - how to jump the first hurdles - (2009-08-20)
[2394] Two days of demonstration scripts in Python - (2009-09-05)
[2504] Learning to program in ... - (2009-11-15)
[2822] Python training courses for use with ESRI ArcMap software - (2010-06-23)
[3076] Python through the Snow - (2010-12-01)
[3463] Busy weekend of contrasts. - (2011-10-03)
[3489] Python courses and Private courses - gently updating our product to keep it ahead of the game - (2011-10-20)
[3519] Python - current versions and implementations (CPython, Jython, IronPython etc) - (2011-11-13)
[3798] When you should use Object Orientation even in a short program - Python example - (2012-07-06)
[3816] Want to escape the Olympics? Learn to program in the countryside! - (2012-07-23)
[3902] Shell - Grep - Sed - Awk - Perl - Python - which to use when? - (2012-10-22)
[3903] Python Programming class for delegates who have already self-taught the basics - (2012-10-25)
[3911] How well do you know Perl and / or Python? - (2012-11-04)
[3935] Whether you have programmed before or not, we can teach you Python - (2012-11-25)
[4236] Using Python to analyse last years forum logs. Good coding practise discussion. - (2014-01-01)
[4295] A longer Python ... training course - (2014-09-16)
[4408] Additional Python courses added to our schedule - (2015-01-29)
[4434] Public training courses - upcoming dates - (2015-02-21)
[4558] Well House Consultants - Python courses / what's special. - (2015-10-28)
[4656] Identifying the first and last records in a sequence - (2016-02-26)
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