Skip to main content

4.7) Typical Errors


Here are some errors you might have come across:

  • SyntaxError: invalid syntax. This can be a missing or wayward bracket, quotation mark, comma, colon, semicolon etc., a missing hash before a comment or a command written in the wrong case (e.g. PRINT instead of print).
  • NameError: name 'xx' is not defined. Wrong variable or function name. Check for typos or wrong case.
  • IndentationError: unexpected indent. Don’t start your lines with a space, unless it’s part of the syntax (e.g. 'if' or 'while' statements, as you will see later on).
  • Silent errors: Some bugs don’t return an error message, but still affect the results of your program. These are more difficult to find because they won’t be highlighted when you try to run your program. For example an operation might return the wrong result because of missing brackets or integer division.

Remember the following rules:

  • Python is case-sensitive: Variable1 is not the same as variable1.
  • Integer division returns an integer in Python 2, although this is no longer the case in Python 3.
  • Python uses indentation as part of its syntax. Spaces in a line don’t usually matter except at the start of the line. Don’t start a line with a space unless you specifically have to.
  • 'Print' statements are required in files (only). You won’t see output when running a program unless you use 'print'. When using Python interactively, values are automatically printed.