Why is __name__ == "__main__" not working?

What is the purpose of the second "print" in this Python code?

  • I got this from a Python tutorial, but he doesn't explain why, after         print(i, end=' '), there is another print().  The code works fine without the second print(), so why's it there? def main(): func() def func(): for i in range(10): print(i, end=' ') print() if __name__ == "__main__": main()

  • Answer:

    print() by itself defaults to end='\n', so it will print out a blank line. I can't say why the tutorial author wanted a blank line to be printed at this point.Typing help(print) will give you more information.

Steve McConville at Quora Visit the source

Was this solution helpful to you?

Other answers

Just to get a blank line between prints of i I think

Dirk Nachbar

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.