Python list comprehension overriding value
Posted
by
Joschua
on Stack Overflow
See other posts from Stack Overflow
or by Joschua
Published on 2011-01-01T20:45:49Z
Indexed on
2011/01/01
20:53 UTC
Read the original article
Hit count: 237
Hi, folks
have a look at the following piece of code, which shows a list comprehension..
>>> i = 6
>>> s = [i * i for i in range(100)]
>>> print(i)
When you execute the code example in Python 2.6 it prints 99, but when you execute it in Python 3.x it prints 6.
What were the reason for changing the behaviour and why is the output 6 in Python 3.x?
Thank you in advance!
© Stack Overflow or respective owner