In this post we will be creating a means of terminating a Python script, to do this we will be using Pythons built-in ‘quit()’ method. It is important to note this would only be practical in interactive interpreter shell, try not to use this in programs.
For this example we will take input from the user, should the input match our if statement the ‘quit()’ method will be invoked thus terminating the Python script.
while True: user_in=input("Exit script? ") if user_in == "y": quit()