mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
gh-129858: Special syntax error for elif
block after else
(#129902)
This commit is contained in:
parent
c3a7118065
commit
99b71efe8e
5 changed files with 137 additions and 75 deletions
|
@ -948,6 +948,18 @@ isn't, there should be a syntax error.
|
|||
...
|
||||
SyntaxError: 'break' outside loop
|
||||
|
||||
elif can't come after an else.
|
||||
|
||||
>>> if a % 2 == 0:
|
||||
... pass
|
||||
... else:
|
||||
... pass
|
||||
... elif a % 2 == 1:
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: 'elif' block follows an 'else' block
|
||||
|
||||
Misuse of the nonlocal and global statement can lead to a few unique syntax errors.
|
||||
|
||||
>>> def f():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue