I am coming from C, C++, and Java background. So I am curious to know why the following Python code works:
def f1():
print(xy)
if __name__ == "__main__":
print("Hello")
xy = 34
f1()
It prints:
Hello
34
How can I access xy
in function f1
? xy
is not defined inside f1
also, xy
is defined in a conditional block of if __name__ == "__main__"
?