[Tutor] What is a semantic error?

Wayne Werner waynejwerner at gmail.com
Sun Jan 23 13:44:16 CET 2011


On Sun, Jan 23, 2011 at 6:09 AM, Richard D. Moores <rdmoores at gmail.com>wrote:

> Is a semantic error one that Python doesn't see as an error -- no
> error is raised; whereas syntax errors aren't errors unless Python
> sees them as "Syntax Error"s?
>
>
Yes:
http://en.wikipedia.org/wiki/Semantic_error

Here is a semantic error:

total = 0
for x in xrange(1,11):
     total = x       # Sums up x

The actual intent was to use += for total.

Another example

# Sums up numbers 1-10 inclusive
total = 0
for x in xrange(1,10):
      total += x

Of course (x)range doesn't include the end index, so in both cases the
program would compile and execute, but neither would give the programmers
intended result.

HTH
-Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110123/5fd7ac57/attachment.html>


More information about the Tutor mailing list