KnowledgeBoat Logo
LoginJOIN NOW

Informatics Practices

Explain the difference between syntax error and runtime error with examples.

Python Funda

1 Like

Answer

Syntax errors are errors that occur due to incorrect format of a Python statement. They occur while the statement is being translated into machine language and before being executed. They are the most common type of errors which are easily traceable. These errors 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, print "Hello World" has 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").

Runtime errors are errors that occur while a program is executing, causing it to crash or behave unexpectedly. These errors are due to invalid operations or conditions that the program encounters during execution, which were not detected during compilation or before the program ran.

For example, 10 * (1/0) will generate runtime error as division of any number by 0 is undefined.

Answered By

3 Likes


Related Questions