Loop Variables Leaking Out!
Does anyone have a sealant? My loop variables are leaking out.
1.
Can you predict the output of this code?
Python 3.5
for x in range(7):if x == 6:print(x, ': for x inside loop')print(x, ': x in global')
But x
was never defined outside the scope of for
loop…
2.
This time, let’s initialize x
first.
Python 3.5
x = -1for x in range(7):if x == 6:print(x, ': for x inside loop')print(x, ': x in global')
3.
Let’s try something new now.
⚠️ The ...