python global variables problem

def change():
    global x
    w.write("zzz")
    x=x+1
    print (x)
    w.close()
if __name__ == "__main__":
    w=open('test.txt','w')
    x=5
    change()

Why has not understood why the change in function can be read w, c language is affected by the impact,
that after this is a separate main function, in fact, just a if, so w, x are global variables.

if __name__ == "__main__":
Published 184 original articles · won praise 19 · views 130 000 +

Guess you like

Origin blog.csdn.net/zhoumingsong123/article/details/88714466