While I was learning LEGB scope rule of python, I wanted a deeper understanding of how global works in python. It seems that even if I refer to an undefined variable(Which is also not in builtins), The code doesn't give me an error. Please help me figure out what actually is happening.
def hey():
    x = 1
    def hey2():
        global ew #ew not defined in the module
        x = 2
        print(x)
    hey2()
    print(x)
hey()
OUTPUT: 2
        1
 
     
     
    