• Home
  • Recent Q&A
  • Java
  • Cloud
  • JavaScript
  • Python
  • SQL
  • PHP
  • HTML
  • C++
  • Data Science
  • DBMS
  • Devops
  • Hadoop
  • Machine Learning
in Python by
Q:
Does Python Language have a Main() method?

1 Answer

0 votes
by
The main() is the entry point function which happens to be called first in most programming languages.

Since Python Language is interpreter-based, so it sequentially executes the lines of the code one-by-one.

Python Language also does have a Main() method. But it gets executed whenever we run our Python Language script either by directly clicking it or starts it from the command line.

We can also override the Python Language default main() function using the Python Language if statement. Please see the below code.

print("Welcome")

print("__name__ contains: ", __name__)

def main():

    print("Testing the main function")

if __name__ == '__main__':

    main()

The output:

Welcome

__name__ contains:  __main__

Testing the main function

Related questions

0 votes
asked Jan 18 in Python by SakshiSharma
+2 votes
asked May 31, 2020 in JAVA by SakshiSharma
...