1def main():
2 print("Hello World!")
3
4if __name__ == "__main__":
5 main()
1#Add this code to run a support module on its own.
2#Great for running quick tests.
3
4if __name__ == "__main__":
5 function_that_starts_the_module_to_run_on_its_own()
6 #or
7 test_function_included_in_module()
1# If the python interpreter is running that module (the source file)
2# as the main program, it sets the special __name__ variable to have
3# a value “__main__”. If this file is being imported from another
4# module, __name__ will be set to the module’s name.
5if __name__=='__main__':
6 # do something
1# It's as if the interpreter inserts this at the top
2# of your module when run as the main program.
3__name__ = "__main__"
1# Suppose this is foo.py.
2
3print("before import")
4import math
5
6print("before functionA")
7def functionA():
8 print("Function A")
9
10print("before functionB")
11def functionB():
12 print("Function B {}".format(math.sqrt(100)))
13
14print("before __name__ guard")
15if __name__ == '__main__':
16 functionA()
17 functionB()
18print("after __name__ guard")