Page 74 - IPP-11
P. 74
The process of finding errors in a program is termed as Debugging.
Due to errors, a program may not execute or may generate wrong output. So it becomes
necessary to find out and remove the errors for the successful execution of a program. Errors
in Python are classified mainly into three types:
(a) Syntax Error
(b) Runtime Error
(c) Logical Error
3.15.1 Syntax Error
A syntax error is an error in the syntax of a sequence of characters or tokens that is intended to
be written in a particular programming language. These types of errors are generated when we
violate the syntax or, in other words, the grammatical rules of a programming language. Syntax
errors are the most common type of errors which are easily traceable. They can be corrected
by the user as the reason for the error and an appropriate message about what is wrong in the
program is displayed.
For example,
Fig. 3.20: Syntax Error: Invalid Syntax
The above statement is an example of syntax error as it violates the language protocol by not
giving parentheses with the print() function. So, the corrected statement should be:
>>> print('Hello world')
Hello world
However, some syntactical errors are quite hard to find. Python is case-sensitive, so you may Python Programming Fundamentals (Additions)
use the wrong case for a variable and find out that the variable isn’t quite working as you
thought it would.
For example,
3.5