# if __name__ == '__main__' checks if a file is imported as a module or not.
# example:
def main():
print('Hello World')
if __name__ == '__main__':
# This code won't run if this file is imported.
main()
print("Hello")
print("__name__ value: ", __name__)
def main():
print("python main function")
if __name__ == '__main__':
main()
# Python program to execute
# main directly
print ("Always executed")
if __name__ == "__main__":
print ("Executed when invoked directly")
else:
print ("Executed when imported")
<class '__main__.CoolClass'>