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