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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
So both iterator variable names should be distinct.