While we are enormously pleased with Python as a programming language for introductory classes, we did note a few issues which were awkward or confusing to Intro students. We want to make it clear in discussing these issues that we are only speaking from the point of view of novice programmers. Experienced programmers might well have very different views.

First, console input presents a problem: input() is not appropriate for strings and raw_input() either requires dealing with types and typecasting or puts us back in the realm of magic. In our experience getting input is one of the largest sources of errors for Python beginners. This has lead to our writing a simple input function which returns an integer, float or string, depending on the input string. (See example on http://tech.canterburyschool.org/pycon/) This function handles our students’ needs but does have the disadvantage of not being part of the language “out of the box”.

A second and related issue for novices is the way Python handles types. In contrast to the rigid insistence upon type compatibility found in C++ and Java, Python seems less predictable to the beginner. Type compatibility is not needed for assignment, is needed logically, but not syntactically, for the comparison and equality operators, and is required for the + operator. Confusion about this behavior is probably the second most common source of errors for inexperienced programmers.

Finally, in common with C++ and Java, Python has different operators for assignment and equality, even though its syntax enforces correct usage. Again like C++ and Java Python uses the same operator for integer or floating point division depending on the types of the arguments. This is a source of confusion to newbies since it is not obvious to them that 3/5 should evaluate differently than 3/5.0, let alone a/b vs. a/float(b). The above issues illustrate why programming is viewed as nearly impossible by the uninitiated. Not only is the logical process of writing a program difficult, one also must deal with picky and apparently arbitrary rules and traps. Thankfully in Python such problems are far fewer than those in C++ or Java.

Download pdf Teaching Programming with Python and PyGame