When the python compiler reads a source file, it executes all the code it finds. Before executing the code, the value of name is set according to whether the currently running module is the main program .
If it is the main program, set it to main
otherwise set it to the module name.
Therefore, when this statement is true, it means that the script currently being executed is the main program.
If there are some commands that are only expected to be executed when the module is run as the main program, and not executed when the module is regarded as a reference module, these commands can be placed after this judgment statement.
Python learning - the role of if __name__ == "__main__"
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325707577&siteId=291194637
Recommended
Ranking