I think it's best to break the answer in depth and in simple words:
__name__ : Every module in Python has a special attribute called __name__.
It is a built-in variable that returns the name of the module.
__main__ : Like other programming languages, Python too has an execution entry point, i.e., main. '__main__' is the name of the scope in which top-level code executes.. Basically you have two ways of using a Python module: Run it directly as a script, or import it. When a module is run as a script, its __name__ is set to __main__.
Thus,the the value of the __name__ attributeattribute is set to __main__ whenwhen the module is run as the main program. Otherwise the value of __name__ is set to contain the name of the module.