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]
Some other articles
Y300 - Python 3 - What is new, what's changed and why A reminder of the key issues to consider in moving from Python 2 to Python 3 Convering from Python 2 to Python 3 - an update, and the 2to3 utility Why populate object with values as you construct them? Object and Static methods - what is the difference; example in Python 3 Progress on moving from Python 2 to Python 3 - training for both versions Testing in Python 3 - unittest, doctest and __name__ == __main__ too. Sorting in Python 3 - and how it differs from Python 2 sorting Moving from Python 2.6 to Python 3 This article Moving the product forward - ours, and MySQL, Perl, PHP and Python too Great new diagrams for our notes ... Python releases Python classes / courses - what version do we train on? The road ahead - Python 3 Python 2 to Python 3 / Python 3000 / Py3k Python 3000 - the next generation Y103 - Conditionals and Loops Conditional operators in Python Equality (in Python) Method, Class, Module, Package - how to they relate in Python? Setting up and tearing down with the Python with keyword Finding sum, minimum, maximum and average in Python (and Ruby) Learning to program - Loop statements such as while Learning to Program - the conditional statement (if) If elif elif elif - multiway selection in Python Identity in Python Flowchart to program - learning to program with Well House Learning to program - the if statement. Python. Finding the total, average, minimum and maximum in a program Python or Lua - which should I use / learn? Python for loops - applying a temporary second name to the same object Does a for loop evaluate its end condition once, or on every iteration? How a for loop works Java, Perl and other languages Python - fresh examples from recent courses Groupsave tickets - 3 or 4 train tickets for the price of 2 This article Saying NOT in Perl, PHP, Python, Lua ... Equality, sameness and identity - Python Decisions - small ones, or big ones? No switch in Python Python is like a narrowboat Python - when to use the in operator New - Conditional expressions in Python 2.5 Python - block insets help with documentation The ternary operator in Python Wimbledon Neck What - no switch or case statement? Y102 - Python - Fundamentals A reminder of the key issues to consider in moving from Python 2 to Python 3 Mutable v Immuatble objects in Python, and the implication Learning to program - variables and constants BODMAS - the order a computer evaluates arithmetic expressions Formatting output - why we need to, and first Python example Some terms used in programming (Biased towards Python) Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. Beware - a=a+b and a+=b are different - Python Python - fresh examples from recent courses This article Variable storage - Perl, Tcl and Python compared Python - fresh examples of all the fundamentals Pascals Triangle in Python and Java Python - input v raw input Question on division (Java) - Also Perl, PHP, Python ... Integer v float - Python Python security - trouble with input Getting rid of variables after you have finished with them Copying a reference, or cloning Making programs easy for any user to start Y050 - Python - General A reminder of the key issues to consider in moving from Python 2 to Python 3 Identifying the first and last records in a sequence Well House Consultants - Python courses / what's special. Public training courses - upcoming dates Additional Python courses added to our schedule A longer Python ... training course Using Python to analyse last years forum logs. Good coding practise discussion. Whether you have programmed before or not, we can teach you Python How well do you know Perl and / or Python? Python Programming class for delegates who have already self-taught the basics Shell - Grep - Sed - Awk - Perl - Python - which to use when? Want to escape the Olympics? Learn to program in the countryside! When you should use Object Orientation even in a short program - Python example Python - current versions and implementations (CPython, Jython, IronPython etc) Python courses and Private courses - gently updating our product to keep it ahead of the game Busy weekend of contrasts. Python through the Snow Python training courses for use with ESRI ArcMap software This article Learning to program in ... Two days of demonstration scripts in Python Learning to program - how to jump the first hurdles Great new diagrams for our notes ... Python releases Learning PHP, Ruby, Lua and Python - upcoming courses Learning Python - many new example programs Python - a truly dynamic language Python training