/ python

What is Python __name__ and __main__

__name__ is the context or scope of the current module the function is running in.

__main__ is the name of the entry module of a Python script.

Imagine that a __main__ module is created automatically for you whenever you run a Python script.

Use of if __name__ == '__main__': basically allows you to define functions that you want to (or not) run if the script is ran directly, or imported.

What is Python __name__ and __main__
Share this