In this code, why do a
and b
not get destroyed at the ends of their respective blocks?
flag = True
if flag:
a = 1
for i in range(2):
b = 2
print(a, b)
Instead, this code prints 1 2
. Why does Python allow this? When can I rely on this behavior?