Differences between revisions 18 and 19
Revision 18 as of 2020-08-21 15:23:18
Size: 3496
Editor: MatsWichmann
Comment:
Revision 19 as of 2021-01-31 18:19:18
Size: 3514
Editor: ChrisM
Comment: Improved write-up and simplified language.
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
 * The [[http://www.alice.org/|Alice]] 3D project developed a 3D programming environment for beginners. They used [[Python]] as the programming language originally (now switched to something else). There were two Python-specific issues found to be problematic for beginners: the case-sensitivity of the language ("variable1" is not the same as "Variable1"), and integer division (a carryover from C, 3/4 = 0, not 0.75, because division of integers returns integers).  Python 3 changed the latter by introducing an explicit integer divison operator, so now 3 / 4 is 0.75 and 3 // 4 = 0. The latter is just part of the language. See [[http://www.linuxjournal.com/article.php?sid=5028|interview]] in Linux Journal and this [[http://www.alice.org/wp-content/uploads/2017/04/ConwayDissertation.pdf|dissertation]] for more details.
 * Indentation. Indentation is part of the Python syntax, used to let the interpreter know which lines belong to a code block (or "suite" as the documentation calls it); leaving out indentation or using the wrong indentation always leads to problems. Often an error is emitted, but if you forget to indent the last line of a block, for example, the code is not considered part of the block and the difference may be more subtle.
 * The [[http://www.alice.org/|Alice]] 3D project developed a 3D programming environment for beginners. Originally, they used [[Python]] but later switched to another language. Two Python-specific issues were found to be problematic for beginners: (1) the case-sensitivity of the language ("variable1" is not the same as "Variable1"), and (2) integer division (a carryover from the programming language C, 3 / 4 = 0, not 0.75, because the division of integers returns integers). Python 3 changed the latter by introducing an explicit integer division operator, so now 3 / 4 is 0.75 and 3 // 4 = 0. The latter is just part of the language. See [[http://www.linuxjournal.com/article.php?sid=5028|interview]] in Linux Journal and this [[http://www.alice.org/wp-content/uploads/2017/04/ConwayDissertation.pdf|dissertation]] for more details.
 * Indentation is part of the Python syntax, used to let the interpreter know which lines belong to a code block (or "suite" as the documentation calls it). Leaving out indentation or using the wrong indentation causes problems. In most of those instances, Python emits an error, but if you forget to indent the last line of a block, for example, the code is not considered part of the block and the difference may result in unrecognized faulty code.
Line 5: Line 5:
 * Changing lists during iteration. A common example is writing a loop over a list, which checks an entry for some condition, which if met, leads to deleting the entry. This will mess up the iteration - to do this safely, iterate over a copy.
 * Not understanding scoping rules, such as "is this global or isn't it?".
 * Changing lists during iteration. A common example is to loop over a list to check an entry for some condition, which, if met, leads to deleting the entry. This will mess up the iteration. To do this safely, iterate over a copy.
 * Not understanding scoping rules, such as "is this global or not?".
Line 8: Line 8:
 * Subtle errors--which may cause some fairly difficult to follow messages--happen when built-in type and function names are "shadowed" (ie. redefined). For example, using `str` as a variable name in a scope (ie. a function or class) will prevent the built-in function of the same name from being usable, producing an error like this: `TypeError: 'str' object is not callable`
 * Even for advanced users there are features of the Python language that can cause difficulties.  See PythonWarts for resources and observations on such matters. These observations have in part been used to suggest refinements in future Python versions.
 * Subtle errors--which may cause some fairly difficult to follow messages--happen when built-in type and function names are "shadowed" (i.e., redefined). For example, using `str` as a variable name in a scope (i.e., a function or class) will prevent the built-in function of the same name from being usable, producing an error like this: `TypeError: 'str' object is not callable`
 * Even for advanced users there are features of the Python language that can cause difficulties. See PythonWarts for resources and observations on such matters. These observations have in part been used to suggest refinements in future Python versions.

Common Problems Beginners Have

  • The Alice 3D project developed a 3D programming environment for beginners. Originally, they used Python but later switched to another language. Two Python-specific issues were found to be problematic for beginners: (1) the case-sensitivity of the language ("variable1" is not the same as "Variable1"), and (2) integer division (a carryover from the programming language C, 3 / 4 = 0, not 0.75, because the division of integers returns integers). Python 3 changed the latter by introducing an explicit integer division operator, so now 3 / 4 is 0.75 and 3 // 4 = 0. The latter is just part of the language. See interview in Linux Journal and this dissertation for more details.

  • Indentation is part of the Python syntax, used to let the interpreter know which lines belong to a code block (or "suite" as the documentation calls it). Leaving out indentation or using the wrong indentation causes problems. In most of those instances, Python emits an error, but if you forget to indent the last line of a block, for example, the code is not considered part of the block and the difference may result in unrecognized faulty code.
  • Forgetting to add a colon (:) at the end of if statements, class declarations, etc.
  • Changing lists during iteration. A common example is to loop over a list to check an entry for some condition, which, if met, leads to deleting the entry. This will mess up the iteration. To do this safely, iterate over a copy.
  • Not understanding scoping rules, such as "is this global or not?".
  • Widely known as the "No Module named..." error, this is an issue all programmers face at some point (sometimes multiple times). This article(The "No Module Named" Error) addresses this issue, going through every possible scenario in which this error occurs and how to avoid running into it again.

  • Subtle errors--which may cause some fairly difficult to follow messages--happen when built-in type and function names are "shadowed" (i.e., redefined). For example, using str as a variable name in a scope (i.e., a function or class) will prevent the built-in function of the same name from being usable, producing an error like this: TypeError: 'str' object is not callable

  • Even for advanced users there are features of the Python language that can cause difficulties. See PythonWarts for resources and observations on such matters. These observations have in part been used to suggest refinements in future Python versions.

  • Some Intermediate Conundrums have been noted with regard to the behavior of some Python features, although these may be outside the scope of beginner problems.

Comments, Potential Solutions

  • The PyChecker module can alert users to many common errors. There also is a tool called PyLint.

  • To see languages that have been used successfully with beginners and children, see Logo, HyperTalk (used in HyperCard and SuperCard), HTML, JavaScript, variants of Basic, etc.

  • Are students learning python to "learn to program" or to develop real applications? Does the IDLE interactive prompt help or hinder either?

Notes

This page was moved from the educational wikis at coedit.net to here.

BeginnerErrorsWithPythonProgramming (last edited 2021-01-31 19:34:47 by MatsWichmann)

Unable to edit the page? See the FrontPage for instructions.