Issue
I don't see any syntax error, do you? The error appears only in ipython, no errors if executed as python script.
$ ipython
IPython 7.16.1 -- An enhanced Interactive Python.
In [1]: x=None
In [2]: if x==42:
...: print('')
...:
In [3]: else:
...: pass
File "<ipython-input-3-9c0a60a8fb6c>", line 1
else:
^
SyntaxError: invalid syntax
Solution
You pressed enter one time more than you should have. The else
block should be immediately after the if
block. What you have now is an else
with no if
.
In [2]: if x==42:
...: print('')
...: else:
...: pass
Answered By - DeepSpace
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.