Hardware Reference
In-Depth Information
continued
Now type this into the Python Shell:
print(zz)
You will see that Python tells you this is a name error (shown in Figure  2-7)
because you have not yet stored a value in the variable name zz , so Python
doesn't yet know about a variable called zz .
FIGURE.2-7 Python tells you about a name error.
Try typing in a while loop, but miss out that all-important colon ( : ) at the end:
while True
Again, you get a syntax error, because Python was expecting the colon but you
did not use it.
Don't be alarmed when you see an error message coming back from your pro-
gram. Look carefully at the line it is talking about and see if you can work out
what you have typed incorrectly. Sometimes you might get a syntax error
because of an error in an earlier line in the program, so check all around the
error message to see if you can figure out what the problem is. If all else fails,
ask a friend to look over your program for you. It is often easier to spot errors in
other peoples programs than your own! When errors are reported on the Python
Shell they also include the line number of the error. You can look at the bottom
right of the IDLE window to see what line number your cursor is at, or you can
use Edit GoTo Line from the IDLE menu.
Syntax refers to the rules of a language (in this case, the Python language), and
is mainly related to the order in which you type things.
 
Search WWH ::




Custom Search