'Inner function not printing nonlocal variable

I have one outer function and 2 inner functions.

def outer():
    x = 'hello'    
    def inner1():
        def inner2():
            nonlocal x
            x = 'python'        
        inner2()
        print(x)
outer()

Please help me understand why the above code is not printing the value of x.

As per my understanding, it should print "hello"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source