you're executing this code from command line therefore if
conditions is true and x
is set. Compare:
>>> if False:
y = 42
>>> y
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
y
NameError: name 'y' is not defined