{"id":3847,"date":"2020-08-10T12:11:40","date_gmt":"2020-08-10T06:41:40","guid":{"rendered":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/?p=3847"},"modified":"2021-07-10T11:35:14","modified_gmt":"2021-07-10T06:05:14","slug":"python-sys-exit","status":"publish","type":"post","link":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/","title":{"rendered":"Why is Python sys.exit better than other exit functions?"},"content":{"rendered":"\n<p>There are many times when we want to exit from the programs after a particular code gets executed, <strong>without even reaching the end of the program. <\/strong>There are many ways in <a href=\"https:\/\/www.pythonpool.com\/python-exit\/\">python to exit from the program.<\/a> Despite having so many ways, python programmers\/ developers generally prefer using <em>sys.exit <\/em>in the real world.<\/p>\n\n\n\n<p><strong>Sys.exit is generally used in programs to raise the SystemExit Exception. With this exception, the program is closed with a proper code passed into the argument.<\/strong><\/p>\n\n\n\n<p>When sys.exit is called, it <strong>raises a SystemExit Exception<\/strong>. In this article, we will learn how to use sys.exit, what arguments we can pass, when it should be used, and many more important things.&nbsp;<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_65 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#Syntax_of_sysexit\" title=\"Syntax&nbsp;of sys.exit()\">Syntax&nbsp;of sys.exit()<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#Parameter_of_sysexit_in_python\" title=\"Parameter of sys.exit in python\">Parameter of sys.exit in python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#Return_Type\" title=\"Return Type\">Return Type<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#How_to_use_sysexit_in_Different_IDES\" title=\"How to use sys.exit in Different IDE\u2019S&nbsp;\">How to use sys.exit in Different IDE\u2019S&nbsp;<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#Without_Argument\" title=\"Without Argument&nbsp;\">Without Argument&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#Using_the_string_type_argument\" title=\"Using the string type argument\">Using the string type argument<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#Using_the_integer_type_argument\" title=\"Using the integer type argument\">Using the integer type argument<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#Using_sysexit_along_with_Try_block_in_python\" title=\"Using sys.exit along with Try block in python\">Using sys.exit along with Try block in python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#Raising_SystemExit_Exception_without_using_python_sysexit\" title=\"Raising SystemExit Exception without using python sys.exit\">Raising SystemExit Exception without using python sys.exit<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#Comparing_the_sysexit_function_with_other_functions_in_python\" title=\"Comparing the sys.exit function with other functions in python\">Comparing the sys.exit function with other functions in python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#Must_Read\" title=\"Must Read:\">Must Read:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#Conclusion\" title=\"Conclusion\">Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-syntax-of-sys-exit\"><span class=\"ez-toc-section\" id=\"Syntax_of_sysexit\"><\/span>Syntax&nbsp;of sys.exit()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Whenever we want to exit from the interpreter explicitly, it means whenever we want to exit from the program before the interpreter reaches the end of the program, we can use sys.exit.&nbsp;&nbsp;<\/strong><\/p>\n\n\n\n<p>Before using sys.exit, we first need to import the \u2018sys\u2019 module into our systems. To import use \u2013 <strong><em>\u2018import sys.\u2019&nbsp;<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>sys.exit([status])&nbsp;<\/strong><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-parameter-of-sys-exit-in-python\"><span class=\"ez-toc-section\" id=\"Parameter_of_sysexit_in_python\"><\/span>Parameter of sys.exit in python<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>sys.exit accepts only <strong>one argument \u2013 status, and that too is optional<\/strong>. If we want to print something while exiting like why we want to exit or something, we can pass that in the argument. It can be either an <strong>integer, float, boolean, or string.&nbsp;<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-return-type\"><span class=\"ez-toc-section\" id=\"Return_Type\"><\/span>Return Type<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p> sys.exit returns<em> SystemExit Exception<\/em> along with the passed argument.&nbsp;<\/p>\n\n\n\n<p><strong>Note<\/strong>&#8211;<em> If we are passing integer 0 as the argument, it means the termination is successful, and if we pass any other argument, it means that the termination is not successful.<\/em>&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-use-sys-exit-in-different-ide-s\"><span class=\"ez-toc-section\" id=\"How_to_use_sysexit_in_Different_IDES\"><\/span>How to use sys.exit in Different IDE\u2019S&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The output is different in different IDE\u2019s. Except for string argument, the output for every other type of argument won\u2019t work for Pycharm.&nbsp;&nbsp;<\/p>\n\n\n\n<p>But first, let us understand to use sys.exit with argument.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-without-argument\"><span class=\"ez-toc-section\" id=\"Without_Argument\"><\/span>Without Argument&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# Importing the sys module which contains exit function\nimport sys\n# Runn the loop 10 times\nfor i in range(10):\n    # Whenever we encounter '7' exit from the loop\n    if i==7:\n        sys.exit()\n    print(i,end=&quot; &quot;)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"344\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/image-3-1024x344.png\" alt=\"python sys.exit\" class=\"wp-image-3848\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/image-3-1024x344.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/image-3-300x101.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/image-3-768x258.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/image-3-1536x516.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/image-3.png 1584w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The output is different for different Integrated Development Environment(IDE).<\/p>\n\n\n\n<p>For Jupyter Notebook,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> 0 1 2 3 4 5 6\n\nAn exception has occurred, use %tb to see the full traceback. <strong>SystemExit<\/strong><\/pre>\n\n\n\n<p>For PyCharm \/ IDLE,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">0\n1\n2\n3\n4\n5\n6<\/pre>\n\n\n\n<p>Now let us learn how to use the arguments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-string-type-argument\"><span class=\"ez-toc-section\" id=\"Using_the_string_type_argument\"><\/span>Using the string type argument<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The output for string type argument remains mostly the same for all IDE&#8217;s.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&lt;pre class=&quot;wp-block-syntaxhighlighter-code&quot;&gt;import sys\n# Create a function that will check whether a function is eligible to vote #or not \ndef is_elegible(ages):\n    # &lt;a href=&quot;https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-iterate-through-list\/&quot; target=&quot;_blank&quot; rel=&quot;noreferrer noopener&quot;&gt;Iterating&lt;\/a&gt; through all the ages\n    for age in ages:\n        if age&lt;18:\n            sys.exit(&quot;The minimum age for voting is 18&quot;)\n\n\nages=&#x5B;19,27,88,12]\nis_elegible(ages)&lt;\/pre&gt;\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"><strong>SystemExit:<\/strong> The minimum age for voting is 18<\/pre>\n\n\n\n<p>You can see that whatever we passed in the argument got printed after the SystemExit Exception.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-integer-type-argument\"><span class=\"ez-toc-section\" id=\"Using_the_integer_type_argument\"><\/span>Using the integer type argument<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>We can pass any integer we want. It can be status code too.<\/p>\n\n\n\n<p>Jupyter Notebook,<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nattendees=&#x5B;&quot;manoj&quot;,&quot;sara&quot;,&quot;sanjay&quot;,&quot;ashwini&quot;]\nif &quot;ashwini&quot; in attendees:\n    sys.exit(0)\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"><strong>SystemExit:<\/strong> 0<\/pre>\n\n\n\n<p>In IDLE or Pycharm, the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Integer_(computer_science)\" target=\"_blank\" rel=\"noreferrer noopener\">integer<\/a> argument would not get printed.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport sys\ndef call_exit():\n    for i in range(1,9):\n        if i==7:\n            print(sys.exit(1))\n        print(i)\n        \ncall_exit()\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">1\n2\n3\n4\n5\n6<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-sys-exit-along-with-try-block-in-python\"><span class=\"ez-toc-section\" id=\"Using_sysexit_along_with_Try_block_in_python\"><\/span>Using sys.exit along with Try block in python<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>We know that, if we are using try-except finally blocks, whatever we print in finally block gets printed for sure. Let us see whether it is true while using sys.exit or not.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfor i in range(10):\n    try:\n    # if i==8, exit\n        if i==8:\n            \n            sys.exit(&quot;We have encountered 8&quot;)\n            \n    except Exception as e:\n        print(&quot;The value of was never 8&quot;)\n    # Whatever happens, this will execute\n    finally:\n        print(i)   \n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">0 1 2 3 4 5 6 7 8\n\nAn exception has occurred, use %tb to see the full traceback. <strong>SystemExit:<\/strong> We have encountered 8<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-raising-systemexit-exception-without-using-python-sys-exit\"><span class=\"ez-toc-section\" id=\"Raising_SystemExit_Exception_without_using_python_sysexit\"><\/span>Raising SystemExit Exception without using python sys.exit<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Another way of exiting the program by raising the SystemExit exception is by using the<strong> raise<\/strong> keyword.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfor i in range(10):\n    if i==5:\n        raise SystemExit(&quot;Encountered 5&quot;)\n    print(i)\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">0 1 2 3 4\n\nAn exception has occurred, use %tb to see the full traceback. <strong>SystemExit:<\/strong> Encountered 5<\/pre>\n\n\n\n<p>It totally depends upon you, which way you want to exit the program. Everything else is the same about the two methods except that, for sys.exit, you have to import sys.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-comparing-the-sys-exit-function-with-other-functions-in-python\"><span class=\"ez-toc-section\" id=\"Comparing_the_sysexit_function_with_other_functions_in_python\"><\/span>Comparing the sys.exit function with other functions in python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Two more ways are <strong>exit() and quit()<\/strong>. But they should <strong>not be<\/strong> used in the <em>production environment because they use the site module<\/em> which is not installed everywhere.<\/p>\n\n\n\n<p>Another Common way for exiting is by using the os._exit(). So let us see what is the difference between the two.<\/p>\n\n\n\n<p><strong>os._exit() <\/strong>method is generally used to exit the process with a specified status without calling any cleanup handlers, flushing stdio buffers, etc. Also, it does not return anything.<\/p>\n\n\n\n<p><strong>Note:<\/strong>&nbsp;This method is normally used in the child process after the <a href=\"https:\/\/www.pythonpool.com\/python-forking\/\" target=\"_blank\" rel=\"noreferrer noopener\">os.fork<\/a> system call. Therefore, os._exit should only be used in some special scenarios.<\/p>\n\n\n\n<p>So, the best way of exiting the program is sys.exit().<\/p>\n\n\n\n<h2 class=\"has-vivid-red-color has-text-color wp-block-heading\" id=\"h-must-read\"><span class=\"ez-toc-section\" id=\"Must_Read\"><\/span>Must Read:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul><li><a href=\"https:\/\/www.pythonpool.com\/python-lowercase\/\">How to Convert String to Lowercase in<\/a><\/li><li><a href=\"https:\/\/www.pythonpool.com\/square-root-in-python\/\">How to Calculate Square Root<\/a><\/li><li><a href=\"https:\/\/www.pythonpool.com\/python-user-input\/\">User Input | Input () Function | Keyboard Input<\/a><\/li><li><a href=\"https:\/\/www.pythonpool.com\/python-book\/\">Best Book to Learn Python<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Whenever we want to exit from the program without reaching the end of the program, we can use the different exit programs available in python. The most standard and commonly used one is the sys.exit() function. We can also usu raise SystemExit to exit out of the program.<\/p>\n\n\n\n<p><em>If you still have any problem or request, do let us know in the comment section below.<\/em><\/p>\n\n\n\n<p><strong>Happy Coding!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are many times when we want to exit from the programs after a particular code gets executed, without even reaching the end of the &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Why is Python sys.exit better than other exit functions?\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/#more-3847\" aria-label=\"More on Why is Python sys.exit better than other exit functions?\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":3867,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[2003,1994,2004,1995,1992,2001,1990,2007,2000,1991,1998,1993],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v22.4) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Why is Python sys.exit better than other exit functions? - Python Pool<\/title>\n<meta name=\"description\" content=\"To exit from the program without reaching the end, we can use python sys.exit function. Other ways are by using exit(), quit() and os._exit().\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-sys-exit\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Why is Python sys.exit better than other exit functions?\" \/>\n<meta property=\"og:description\" content=\"There are many times when we want to exit from the programs after a particular code gets executed, without even reaching the end of the program. There are\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-sys-exit\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-10T06:41:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-10T06:05:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-6.png\" \/>\n\t<meta property=\"og:image:width\" content=\"264\" \/>\n\t<meta property=\"og:image:height\" content=\"159\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ashwini Mandani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashwini Mandani\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-sys-exit\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-sys-exit\/\"},\"author\":{\"name\":\"Ashwini Mandani\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056\"},\"headline\":\"Why is Python sys.exit better than other exit functions?\",\"datePublished\":\"2020-08-10T06:41:40+00:00\",\"dateModified\":\"2021-07-10T06:05:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-sys-exit\/\"},\"wordCount\":748,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-sys-exit\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-6.png\",\"keywords\":[\"how to use sys.exit in python\",\"python 3 sys.exit\",\"python 3 sys.exit codes\",\"python sys.exit\",\"python sys.exit vs os._exit\",\"python sys.exit()\",\"python sys.exit(1)\",\"sys.exit in python\",\"sys.exit python\",\"sys.exit python 3\",\"sys.exit() python\",\"sys.exit() python 3\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-sys-exit\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/python-sys-exit\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-sys-exit\/\",\"name\":\"Why is Python sys.exit better than other exit functions? - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-sys-exit\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-sys-exit\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-6.png\",\"datePublished\":\"2020-08-10T06:41:40+00:00\",\"dateModified\":\"2021-07-10T06:05:14+00:00\",\"description\":\"To exit from the program without reaching the end, we can use python sys.exit function. Other ways are by using exit(), quit() and os._exit().\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-sys-exit\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-sys-exit\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-sys-exit\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-6.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-6.png\",\"width\":264,\"height\":159,\"caption\":\"Python sys.exit\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-sys-exit\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Why is Python sys.exit better than other exit functions?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/twitter.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056\",\"name\":\"Ashwini Mandani\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/efd3e2763a755a226df4479ad87a5464?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/efd3e2763a755a226df4479ad87a5464?s=96&d=wavatar&r=g\",\"caption\":\"Ashwini Mandani\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Why is Python sys.exit better than other exit functions? - Python Pool","description":"To exit from the program without reaching the end, we can use python sys.exit function. Other ways are by using exit(), quit() and os._exit().","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/","og_locale":"en_US","og_type":"article","og_title":"Why is Python sys.exit better than other exit functions?","og_description":"There are many times when we want to exit from the programs after a particular code gets executed, without even reaching the end of the program. There are","og_url":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/","og_site_name":"Python Pool","article_published_time":"2020-08-10T06:41:40+00:00","article_modified_time":"2021-07-10T06:05:14+00:00","og_image":[{"width":264,"height":159,"url":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-6.png","type":"image\/png"}],"author":"Ashwini Mandani","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Ashwini Mandani","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/#article","isPartOf":{"@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/"},"author":{"name":"Ashwini Mandani","@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056"},"headline":"Why is Python sys.exit better than other exit functions?","datePublished":"2020-08-10T06:41:40+00:00","dateModified":"2021-07-10T06:05:14+00:00","mainEntityOfPage":{"@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/"},"wordCount":748,"commentCount":1,"publisher":{"@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/#primaryimage"},"thumbnailUrl":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-6.png","keywords":["how to use sys.exit in python","python 3 sys.exit","python 3 sys.exit codes","python sys.exit","python sys.exit vs os._exit","python sys.exit()","python sys.exit(1)","sys.exit in python","sys.exit python","sys.exit python 3","sys.exit() python","sys.exit() python 3"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/","url":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/","name":"Why is Python sys.exit better than other exit functions? - Python Pool","isPartOf":{"@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/#primaryimage"},"image":{"@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/#primaryimage"},"thumbnailUrl":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-6.png","datePublished":"2020-08-10T06:41:40+00:00","dateModified":"2021-07-10T06:05:14+00:00","description":"To exit from the program without reaching the end, we can use python sys.exit function. Other ways are by using exit(), quit() and os._exit().","breadcrumb":{"@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/#primaryimage","url":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-6.png","contentUrl":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Fibonacci-series-in-Python-6.png","width":264,"height":159,"caption":"Python sys.exit"},{"@type":"BreadcrumbList","@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/python-sys-exit\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Why is Python sys.exit better than other exit functions?"}]},{"@type":"WebSite","@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/#website","url":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/twitter.com\/pythonpool","https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056","name":"Ashwini Mandani","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/secure.gravatar.com\/avatar\/efd3e2763a755a226df4479ad87a5464?s=96&d=wavatar&r=g","contentUrl":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/secure.gravatar.com\/avatar\/efd3e2763a755a226df4479ad87a5464?s=96&d=wavatar&r=g","caption":"Ashwini Mandani"}}]}},"_links":{"self":[{"href":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3847"}],"collection":[{"href":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=3847"}],"version-history":[{"count":7,"href":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3847\/revisions"}],"predecessor-version":[{"id":14497,"href":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3847\/revisions\/14497"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/3867"}],"wp:attachment":[{"href":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=3847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=3847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=3847"}],"curies":[{"name":"wp","href":"https:\/\/web.archive.org\/web\/20240926035910\/https:\/\/api.w.org\/{rel}","templated":true}]}}