Skip to content

Commit 1db6345

Browse files
authored
Update syntax error example in tutorial
Clarify error message explanation for syntax errors.
1 parent 1a0edb1 commit 1db6345

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Doc/tutorial/errors.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ Syntax Errors
1717
Syntax errors, also known as parsing errors, are perhaps the most common kind of
1818
complaint you get while you are still learning Python::
1919

20-
>>> while True print('Hello world')
20+
>>> a[1]] = 0
2121
File "<stdin>", line 1
22-
while True print('Hello world')
23-
^^^^^
24-
SyntaxError: invalid syntax
25-
26-
The parser repeats the offending line and displays little arrows pointing
27-
at the place where the error was detected. Note that this is not always the
28-
place that needs to be fixed. In the example, the error is detected at the
29-
function :func:`print`, since a colon (``':'``) is missing just before it.
22+
a[1]] = 0
23+
^
24+
SyntaxError: unmatched ']'
25+
26+
The parser repeats the offending line and displays a little arrow pointing
27+
at the earliest point in the line where the error was detected.
28+
Note that this is not always the place that needs to be fixed.
29+
In the example, the arrow points to the extra ``]`` bracket, which is where the
30+
error is detected.
3031

3132
The file name (``<stdin>`` in our example) and line number are printed so you
3233
know where to look in case the input came from a file.

0 commit comments

Comments
 (0)