how to close python in terminal code example Example 1: exit python terminal Ctrl+d or exit() Example 2: how to code python to close a program import sys sys.exit(0)