Skip to main content
Active reading.
Source Link
Peter Mortensen
  • 31.1k
  • 22
  • 111
  • 134

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.

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 value of __name__ attribute is set to __main__ when the module is run as main program. Otherwise the value of __name__ is set to contain the name of the module.

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 value of the __name__ attribute is set to __main__ when the module is run as the main program. Otherwise the value of __name__ is set to contain the name of the module.

deleted 2 characters in body
Source Link
Xantium
  • 11.7k
  • 12
  • 72
  • 96

I think it's best to break the answer in depth and in simple words:

name__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__main__ : Like other programming languages, Python too has an execution entry point i.e. main. '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 value of __name__ attribute is set to __main__ when the module is run as main program. Otherwise the value of __name__ is set to contain the name of the module.

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 value of __name__ attribute is set to __main__ when the module is run as main program. Otherwise the value of __name__ is set to contain the name of the module.

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 value of __name__ attribute is set to __main__ when the module is run as main program. Otherwise the value of __name__ is set to contain the name of the module.

Source Link
Taufiq Rahman
  • 5.8k
  • 3
  • 39
  • 45

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 value of __name__ attribute is set to __main__ when the module is run as main program. Otherwise the value of __name__ is set to contain the name of the module.