Dark theme

Issues with variables


To see this in action, download run this file at the command prompt: test2.py. You should see the following:


  File

This time, if you look carefully, you can see there's an extra piece of information, a tiny caret symbol ("^") trying to point to the actual problem in the line. This sometimes appears when Python thinks it can work out where the issue is. As it happens, here it hasn't done so well at this.

The error message this time is SyntaxError: EOL while scanning string literal. This means we've mistyped something. Specifically it has reached the end of the line ("EOL"; "EOF" is end of file) trying to read a string literal (a piece of text). As text can only be multi-line between triple-quotes (""" or '''), it has got confused. Any string starting with a double quote should end with another double quote before the next line starts. Because of this, it has put the caret at the end of the end of the file. The solution is to add in another double quote, thus:

print("aa =" aa)

Now, there is no way you could particularly know this as a beginner – it is the kind of thing you recognise when you've learnt the syntax, but it does at least suggest something is going wrong with a string on line 4, which is the key thing.

Fix the code, and then move on to the next part where we'll practice debugging using the Python messages.