how to exit out of a python script code example Example 1: exit python script import sys sys.exit() Example 2: python how to exit function return None