How do I abort the execution of a Python script? [duplicate]

I have a simple Python script that I want to stop executing if a condition is met.

For example:

done = True
if done:
    # quit/stop/exit
else:
    # do other stuff

Essentially, I am looking for something that behaves equivalently to the ‘return’ keyword in the body of a function which allows the flow of the code to exit the function and not execute the remaining code.

8 Answers
8

Leave a Comment