[Tutor] python errors

Alan Gauld alan.gauld at btinternet.com
Mon Apr 14 18:25:09 CEST 2014


On 14/04/14 12:53, keith papa wrote:
> Hi am a new to programming and I reading the book "Think python" am on
> chapter one and it mentioned some errors I need to look out for like:
> Syntax errors, Runtime errors and semantic errors. I wanted to know
> if you guys have some  examples of the errors?

You will create your own examples soon enough! :-)

But if you want to see what some look like try the following
(assuming you use Python v3)

Syntax error (The code is not valid python):

 >>> print "Python rocks!"

Runtime error (The code is valid but the result is
not due to runtime issues):

 >>> foo = []
 >>> print(foo[2])

Semantic error (The code/design is logically wrong even
if valid syntactically)

 >>> x = "foo" - 4

Try those in the interpreter and see what happens.



-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list