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