mardi 17 septembre 2019

Calling a Function Through an If-Statement in Python

I was following a tutorial to build a simple port scanner, and the instructor used the following syntax to call a function, but, they didn't really explain the syntax.

Syntax

if __name__ == '__main__':
     main()

Questions

  1. Is this the same as saying, if main() is called somewhere in this script, run main()?
  2. If the above is true, why wouldn't you just run main() when you needed it elsewhere in the code?

Aucun commentaire:

Enregistrer un commentaire