Why use def main()? [duplicate] September 11, 2022 by Tarik Without the main sentinel, the code would be executed even if the script were imported as a module.