mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Docs: Update SyntaxError message in REPL example for list comprehension (GH-93901) (GH-94425)
(cherry picked from commit 22b783aba0
)
Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
This commit is contained in:
parent
a548a45633
commit
cbd562ff4e
1 changed files with 3 additions and 3 deletions
|
@ -268,10 +268,10 @@ it must be parenthesized. ::
|
||||||
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]
|
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]
|
||||||
>>> # the tuple must be parenthesized, otherwise an error is raised
|
>>> # the tuple must be parenthesized, otherwise an error is raised
|
||||||
>>> [x, x**2 for x in range(6)]
|
>>> [x, x**2 for x in range(6)]
|
||||||
File "<stdin>", line 1, in <module>
|
File "<stdin>", line 1
|
||||||
[x, x**2 for x in range(6)]
|
[x, x**2 for x in range(6)]
|
||||||
^
|
^^^^^^^
|
||||||
SyntaxError: invalid syntax
|
SyntaxError: did you forget parentheses around the comprehension target?
|
||||||
>>> # flatten a list using a listcomp with two 'for'
|
>>> # flatten a list using a listcomp with two 'for'
|
||||||
>>> vec = [[1,2,3], [4,5,6], [7,8,9]]
|
>>> vec = [[1,2,3], [4,5,6], [7,8,9]]
|
||||||
>>> [num for elem in vec for num in elem]
|
>>> [num for elem in vec for num in elem]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue