1. New style classes take on the old style class format
But does it matter if you explicity inherit in Python 3??
2. print moves from being a keyword to a function
Single value tuple as parameter will work in both cases
You may also do a sys.stdout.write
3. integer division using "/" returns a float
Use // if you need the whole number back
4. raw_input becomes input
Thank goodness ;-)
5. sort's callback changes to a "key =" type using a single parametered lambda
But remember you have things like sorted backported to 2.7
6. Text strings d[83][c2]áfaut to unicode in Python 3
7. You need all your modules and dependencies sorted out for Python 3 before you switch to that
8. You can't use new Python 3 stuff in Python 2 unless it's been backportd
In most cases, it's practical to write code that works with both Python2 and Python 3. However, if you must write something a bit different, you can use:
if sys.version_info < (3,0):
and you do need to remember that even if you do this, the syntax must be compatible with both the Python 2 and Python 3 compilers!
(written 2016-10-30)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
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)
[2778] Learning to program in Python 2 ... and / or in Python 3 - (2010-05-24)
[3083] Python - fresh examples from recent courses - (2010-12-11)
[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)
[2285] Great new diagrams for our notes ... Python releases - (2009-07-13)
[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)
Y199 - Python - Fast Start [4707] Some gems from an introduction to Python - (2016-10-29)
[4709] Some gems from Intermediate Python - (2016-10-30)
[4713] Equality (in Python) - (2016-10-30)
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)
[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)
Some other Articles
Profiling your Python programWell House Manor - Still five out of five!The technical article feed continues - personal updates more proactive on Facebook now!A reminder of the key issues to consider in moving from Python 2 to Python 3Searching a Json or XML structure for a specific key / value pair in PythonScons - a build system in Python - building hello world