Categories
Python Answers

How to terminate a script with Python?

Spread the love

Sometimes, we want to terminate a script with Python

in this article, we’ll look at how to terminate a script with Python.

How to terminate a script with Python?

To terminate a script with Python, we can call sys.exit.

For instance, we write

import sys

sys.exit()

to call sys.exit with an optional exit code argument.

If we call it with anything other than 0, we exit the script with an abnormal termination.

Conclusion

To terminate a script with Python, we can call sys.exit.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *