Python by Swaroop C H - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Errors

Consider a simpleprint statement. What if we misspeltprint asPrint? Note the capitalization. In this case, Python raises a syntax error.

 

>>> Print 'Hello World' File "<stdin>", line 1 Print 'Hello World' ^ SyntaxError: invalid syntax >>> print 'Hello World' Hello World

 

Observe that aSyntaxError is raised and also the location where the error was detected is printed. This is what an error handler for this error does.