The Importance of if __name__ == “__main__”: in Python


Protect code in a script from being executed when imported as a module.

Source Code

def main():
    print("Hello, world!")
if __name__ == "__main__":
    main()
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments