Is “__main__” just a string literal?

  • A+
Category:Languages

I have just started learning Python and one thing is bugging me is the exact type of "__main__". So far, I have seen that "__main__" is mostly used as string literal like __name__ == "__main__".
I mean, it is not a function, it is not a variable. With all the other built-in variables and functions starting with __ it is just confusing. Any special reason it has to start with __? I know it has special meaning in the context of modules and namespaces, but I am talking purely in the terms of basic/primitive data types.

 


Yes, "__main__" is a string literal, since module names are strings. The module is called __main__ to distinguish it from modules named main, and since it is a system-assigned name.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: