You get a
In this case it doesn't matter, that the name z is global.
In the context of the list comprehension the name z is a local variable, because it's assigned.
You may ask now, where the assignment happens:
for z in range(z+1)
The red one, is the assignment of local variable z. The green is read access to the variable.
Just change the z into z_ and the code works.
Error:UnboundLocalError: local variable 'z' referenced before assignment
The cause is, you're referencing z before it has been assigned.In this case it doesn't matter, that the name z is global.
In the context of the list comprehension the name z is a local variable, because it's assigned.
You may ask now, where the assignment happens:
for z in range(z+1)
The red one, is the assignment of local variable z. The green is read access to the variable.
Just change the z into z_ and the code works.
print([[x,y,z_] for i in range(x+1) for j in range(y+1) for z_ in range(z+1)])
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!