list comprehensions put non-names into namespaces!

Terry Reedy tjreedy at udel.edu
Fri May 26 14:09:23 EDT 2006


"Mel Wilson" <mwilson-to at sympatico.ca> wrote in message 
news:7hBdg.2071$ho5.166428 at news20.bellglobal.com...
> Point of information, would this be the interpreter putting
> the result of its last calculation in _ ?

Yes, in interactive mode (but not in batch mode) it binds the valid name 
'_' to the result of statement expressions.

> >>> [2*x for x in range(5)]
> [0, 2, 4, 6, 8]
> >>> _[4]
> 8

which here is the list.

Terry Jan Reedy






More information about the Python-list mailing list