This code is perfectly valid Python
x=[[1,2,3,4], [11,22,33,44]]
for e in x:
for e in e:
print e
Can someone please tell me why, and how this works?
I understand that both the e‘s are in different scopes, but how come using them together like this isn’t causing an error?
The scopes aren’t different; in Python a function has a single local scope (as does code entered at global level in the console).
The reason the code is OK is that you finish using the outer value of
ebefore you rebind it to the inner values; try looking at what this prints: