I find out what is exitnot a keyword in Python,
exit
import keyword print('exit' in keyword.kwlist) # Output: False
But when using this word no NameError: name 'exit' is not defined. The output of the following code allows me to be confused. Can anyone help me out?
NameError: name 'exit' is not defined
for i in range(5): print(i) cur=i if i<2 else exit print(cur) # Output 0 1 2 3 4 Use exit() or Ctrl-D (i.e. EOF) to exit
I cannot get related information exitfrom the Python documentation except exit([code=None]).
exit([code=None])
python. (, for, del, if...). . , .
for
del
if
(, , , ), python . , sorted, id, vars,...
sorted
id
vars
, exit - , . sys.exit.
sys.exit
exit - Quitter. Quitter __repr__, , exit . __call__. , __init__ , , __call__, . exit() __call__, .
Quitter
__repr__
__call__
__init__
exit()
exit - sys.exit, .
, (, sum, int...). , ,
sum
int