how could it works if function is called before it is defined in python?
Posted
by
user2131316
on Stack Overflow
See other posts from Stack Overflow
or by user2131316
Published on 2013-11-12T21:34:33Z
Indexed on
2013/11/12
21:54 UTC
Read the original article
Hit count: 186
I was wondering what does if __name__ == "__main__":
really do in python, I have the following code in python3:
def main():
test();
def test():
print("hello world " + __name__);
if __name__ == "__main__":
main();
we know that we have to declare a function before we use it, so function call inside of if
part works fine, the main()
is defined before it is called inside of if
statement, but what about the test() function, it is defined after it is called and there is no errors:
def main():
test();
def test():
print("hello world " + __name__);
so how could it works if the test()
function is defined after it is called?
© Stack Overflow or respective owner