using exit python code example Example 1: python exit program import sys sys.exit() Example 2: python how to exit function return None