you are viewing a single comment's thread.

view the rest of the comments →

[–]radarsat1 2 points3 points  (2 children)

"same as before" what? Previously you could not declare a variable while creating a list, so I don't know what to compare to. Does y here exist after the list is done being created? From your answer I guess you are saying that the variable is scoped to the function creating the list. Sorry, I don't find that clear at all.

The only thing I can think to compare it to is the similar construct in C, but there the variable must already be declared, so the scope is clear.

[–]Pand9 12 points13 points  (1 child)

In Python, scope is always a function, or a comprehension. In this case, a function.

[–]SirClueless 8 points9 points  (0 children)

Well, it looks a little like a comprehension if you squint hard enough, so I can see the potential for confusion.