I have seen some python code having "main(_)" function instead of "main()". What is the difference between these two main functions?
Asked
Active
Viewed 995 times
0
-
1One takes an argument called `_`, the other doesn't. `main()` is not significant to python like it is in some other languages. – AChampion Feb 18 '19 at 02:04
-
Refer to this question. https://stackoverflow.com/questions/22492162/understanding-the-main-method-of-python – Jim Todd Feb 18 '19 at 02:07
1 Answers
1
There is no particular significance to the main function in Python (unlike C, for example, where it's the entry point for hosted implementations).
You'll often see code in a module like:
if __name__ == "__main__":
main()
so that running it and importing it will result in different behaviour. But there's nothing magical about the main name (or parameters that it takes), you could just as easily use:
if __name__ == "__main__":
xyzzy('plugh', 'twisty-passages')
In Python, the difference between main() and main(_) is that the latter takes a parameter called _. That's it, really.
paxdiablo
- 854,327
- 234
- 1,573
- 1,953