Is it expected that nested variables in Python overlaps? for example:
for i in range(1,10):
x = [0xFF for i in range(6)]
print(i)
what is the expected result (sequence) ? With Python 2.7 I'm getting nine fives.
What you see is a side-effect of using list comprehensions. The iterator variable inside the list comprehension is identical with the one of the for loop. This means that the iterator variable of the list comprehension is not local the expressions itself.
Example:
>>> [x for x in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> print x
9
So both iterator variable names should be distinct.
When you declare any variable it will be store the value. In python when you initialise any variable and store some value it will be available till the variable will not destroy. So when you write x = 10 inside the loop you will get the x out side the loop also. If you want to delete that variable then type del x then you will not get the value of the x