Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6078839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:52:43+00:00 2026-05-23T10:52:43+00:00

In Python, there are two similarly-named functions, exit() and sys.exit() . What’s the difference

  • 0

In Python, there are two similarly-named functions, exit() and sys.exit(). What’s the difference and when should I use one over the other?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:52:44+00:00Added an answer on May 23, 2026 at 10:52 am

    exit is a helper for the interactive shell – sys.exit is intended for use in programs.

    The site module (which is imported automatically during startup, except if the -S command-line option is given) adds several constants to the built-in namespace (e.g. exit). They are useful for the interactive interpreter shell and should not be used in programs.


    Technically, they do mostly the same: raising SystemExit. sys.exit does so in sysmodule.c:

    static PyObject *
    sys_exit(PyObject *self, PyObject *args)
    {
        PyObject *exit_code = 0;
        if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code))
            return NULL;
        /* Raise SystemExit so callers may catch it or clean up. */
        PyErr_SetObject(PyExc_SystemExit, exit_code);
       return NULL;
    }
    

    While exit is defined in site.py and _sitebuiltins.py, respectively.

    class Quitter(object):
        def __init__(self, name):
            self.name = name
        def __repr__(self):
            return 'Use %s() or %s to exit' % (self.name, eof)
        def __call__(self, code=None):
            # Shells like IDLE catch the SystemExit, but listen when their
            # stdin wrapper is closed.
            try:
                sys.stdin.close()
            except:
                pass
            raise SystemExit(code)
    __builtin__.quit = Quitter('quit')
    __builtin__.exit = Quitter('exit')
    

    Note that there is a third exit option, namely os._exit, which exits without calling cleanup handlers, flushing stdio buffers, etc. (and which should normally only be used in the child process after a fork()).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a Ruby equivalent for Python's is? It tests whether two objects are
in languages like PHP or Python there are convenient functions to turn an input
Is there any python module to convert PDF files into text? I tried one
Is there any elegant way of splitting a list/dict into two lists/dicts in python,
In python there are two ways to declare decorators: Class based class mydecorator(object): def
In Python there is a really neat function called zip which can be used
In Python there is a maximum recursion depth. Seems it is because Python is
I'm looking for presence of an element in a list. In Python there is
In Python is there any way to make a class, then make a second
Is there a Python class that wraps the file interface (read, write etc.) around

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.