
python.list at tim
May 2, 2012, 6:23 PM
Post #2 of 2
(158 views)
Permalink
|
|
Re: Why variable used in list comprehension available outside?
[In reply to]
|
|
On 05/02/12 19:52, Peng Yu wrote: > The following example demonstrates the variable 'v' used in the > list comprehension is accessible out site the list > comprehension. It did in Python 2.x but has been fixed in 3.x: tim [at] bigbo:~$ python3 Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = 42 >>> [x for x in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> x 42 >>> tim [at] bigbo:~$ python2.6 Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = 42 >>> [x for x in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> x 9 >>> -tkc -- http://mail.python.org/mailman/listinfo/python-list
|