What is the Difference Between quit() and exit() commands in Python?
Peter Otten
__peter__ at web.de
Mon Sep 16 08:51:19 EDT 2019
Hongyi Zhao wrote:
> What is the Difference Between quit() and exit() commands in Python?
They are instances of the same type
>>> import inspect
>>> type(quit) is type(exit)
True
>>> print(inspect.getsource(type(quit)))
class Quitter(object):
def __init__(self, name, eof):
self.name = name
self.eof = eof
def __repr__(self):
return 'Use %s() or %s to exit' % (self.name, self.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)
There is no difference, except for the name attribute and the repr() text:
>>> exit.name, exit.eof, exit
('exit', 'Ctrl-D (i.e. EOF)', Use exit() or Ctrl-D (i.e. EOF) to exit)
>>> quit.name, quit.eof, quit
('quit', 'Ctrl-D (i.e. EOF)', Use quit() or Ctrl-D (i.e. EOF) to exit)
More information about the Python-list
mailing list