Episode #29 | Types of Python Error Messages

Thursday, 16 May 2019 Kudzai Nyandoro 3:05 Minutes


We learned about how to get help from Python in the last episode. In this episode, we are going learn about the three types of error messages that Python gives us and these are; syntax errors, runtime errors, and logical or semantic errors


  1. Syntax errors: These occur when we violate the structural rules of a program.
# Example, we cannot use numbers as variable names.
>>> 99 = age
  File "<stdin>", line 1
SyntaxError: can't assign to literal
  1. Runtime errors: This occurs during runtime when Python is forced to abruptly exit a program during execution after encountering a runtime error. Runtime errors are also known as exceptions.
# Example, we cannot divide a number by zero
>>> 100/0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
  1. Logical or Semantic errors: These are the hardest to identify because no error messages is given. The program runs from start to finish and returns the wrong result.
# Example, python returns a tuple instead of the number 1 million.
# A tuple an immutable Python sequence type and are going to discuss more on later in future screencasts.
>>> num = 1,000,000
>>> num
(1, 0, 0)