RE: Why and when to use Python’s `__name__ == “__main__”`?
In Python, `if __name__ == "__main__":` is used to determine whether the script is being run directly or it's being imported as a module. When a script is run directly, Python sets the `__name__` variable to be `"__main__"`, allowing the code under the `if __name__ == "__main__":` to run. If the script is being imported as a module, `__name__` is set to the module's name and the code under the `if __name__ == "__main__":` statement won't run. This is used for code that you only want to execute if the file is being run directly, not when it's imported as a module in another script. For example, tests or other code e.g., print statements that checks the functionality of the script 'directly' can be put under this clause to avoid them being run when the script is imported as a module elsewhere. So to summarize, use `if __name__ == "__main__":` to prevent certain parts of code from being run when the module is imported.