How to End a Python Program

To end a Python program, press one of the following key combos depending on your system:

  • CTRL + C on Windows.
  • Control + C on Mac.

How to End the Interactive Python Command-Line Session

To leave the interactive Python command-line session, press:

  • CTRL + Z on Windows.
  • Control + Z on Mac.

Or run the exit() function in your session:

>>> exit()

How to Terminate a Python Script

If you need to end a Python program from the code, use the sys.exit() function.

Before you do that make sure to import the sys library.

For example:

import sys
sys.exit()

Conclusion

Thanks for reading. I hope you got your program to stop 🙂

Happy coding!

Further Reading

50 Python Interview Questions with Answers

50+ Buzzwords of Web Development

Share this article with others:

Share on twitter
Share on linkedin
Share on facebook
Share on pinterest
Share on email

Learn these 10 tips to write professional code.

Make your coding life easier with these amazing command-line tools

Learn how to use latest advancements in AI to write faster.

Leave a Comment

Your email address will not be published.