exit from python shell code example Example 1: exit python terminal Ctrl+d or exit() Example 2: exit python script import sys sys.exit()